static import

J

jalina

Is there something like the static import of java in C++ ? That is to
say to define an alias to a static variable of a class.

For example, if:

class A {
public:
static int sfield;
};

I want to be able to do something like (which I know is not valid):

using A::sfield; <== define sfield as an alias for A::sfield

// ....

sfield = 99; <== sfield is A::sfield


Thank you
 
J

Jerry Coffin

Is there something like the static import of java in C++ ? That is to
say to define an alias to a static variable of a class.

For example, if:

class A {
public:
static int sfield;
};

I want to be able to do something like (which I know is not valid):

[ ... ]

int &sfield = A::sfield;
sfield = 99; <== sfield is A::sfield

Should now work.
 
D

Darwin Lalo

jalina said:
Is there something like the static import of java in C++ ? That is to
say to define an alias to a static variable of a class.

For example, if:

class A {
public:
static int sfield;
};
class -> namespace
I want to be able to do something like (which I know is not valid):

using A::sfield; <== define sfield as an alias for A::sfield

// ....

sfield = 99; <== sfield is A::sfield


Thank you
 
T

Tomás

class A {
public:

static int sfield;

struct Monkey {
int k;
};

};

int main()
{
//Use a reference for the static data:

int& sfield = A::sfield;

//Use a typedef for the types it contains:

typedef A::Monkey Monkey;


//Now proceed:


sfield = 7;


Monkey object;
object.k = 6;

}


Tomás
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top