By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

static import

P: n/a
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

Apr 24 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <44***********************@news.wanadoo.fr>,
ja****@nospam.please.com says...
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.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Apr 24 '06 #2

P: n/a

jalina wrote:
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


Apr 24 '06 #3

P: n/a

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
Apr 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.