static variable

C

Carmen Sei

does static in C++ is exactly the same as in Java?

the following static variable is Class variable that I can call by
Class Name

Configuration.RemoteType = xx;

#######################

class Configuration {
public:
Configuration();
void Initialize();

public:
static RemoteType RemoteType;
static ControllerType ControllerType;

};
 
P

Paavo Helde

does static in C++ is exactly the same as in Java?

Most probably not - static is a heavily overloaded keyword in C++. In
this case (class static data members) I believe the meaning is similar
though. Note that you need separate definition/initialization of static
data members outside of the class definition in C++, not sure about Java.
the following static variable is Class variable that I can call by
Class Name

Configuration.RemoteType = xx;
In C++ this reads:
Configuration::RemoteType = xx;
#######################

class Configuration {
public:
Configuration();
void Initialize();

public:
static RemoteType RemoteType;
static ControllerType ControllerType;

You cannot have the variable name same as the type!

Regards
Paavo
 
R

rohitganda

does static in C++ is exactly the same as in Java?

the following static variable is Class variable that I can call by
Class Name

Configuration.RemoteType = xx;

#######################

class Configuration {
public:
        Configuration();
        void Initialize();

public:
        static RemoteType RemoteType;
        static ControllerType ControllerType;



};- Hide quoted text -

- Show quoted text -

The question is not very much clear. In what sense are you comparing
the two. If you mean that you can acess the variable without
instantiating an object, I think yes they are same but the systax is
different.

Java: ClassName.Staticvar = SomeValue;

C++: ClassName::StaticVar = SomeValue;

Hope this helps.
- Rohit
 
J

James Kanze

does static in C++ is exactly the same as in Java?

Not really. To begin with, many of the contexts where you might
use static in C++ don't exist in Java.

Static member variables in C++ are fairly similar to static
member variables in Java, at least if you abstract the dynamic
loading of Java.
the following static variable is Class variable that I can
call by Class Name
Configuration.RemoteType = xx;

class Configuration {
public:
Configuration();
void Initialize();
public:
static RemoteType RemoteType;
static ControllerType ControllerType;
};

The syntax is different in C++. There is no instance of the
class type itself, and you use the scope resolution operator to
access static class members, e.g.: Configuration::RemoteType.
(Alteratively, if you have an instance, you can access the
variable just as if it were a non-static member of that
instance.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top