Need Help with static struct class definition

S

SteveM

This is probably an easy answer but since I am fairly new to C++ for
some reason I can't see it :-( Any help would be appreciated
:)

I have a class:

class AClass
{
public:
.
. (some functions)
private:
struct PData
{
static int aValue;
static int bValue;
}
}

I am clueless as to how to format the definition. Everything I have
tried up till now has been flagged by the compiler
Please Help

BTW What I am needing to do is make the variables of the struct
available to static functions (in public of this class). if I need to
make the struct static also or just need the struct static but not the
members I really dont care. The ultimate goal here is to 1.) get
something to work 2.) Get a better understanding of how C++ does things
(such as static structs or static members of structs)

Thanks for the help :)
 
V

Victor Bazarov

SteveM said:
This is probably an easy answer but since I am fairly new to C++ for
some reason I can't see it :-( Any help would be appreciated
:)

I have a class:

class AClass
{
public:
.
. (some functions)
private:
struct PData
{
static int aValue;
static int bValue;
}

Missing a semicolon here

And here
I am clueless as to how to format the definition.

What do you mean by "format the definition"?
> Everything I have
tried up till now has been flagged by the compiler

Flagged how?
Please Help

BTW What I am needing to do is make the variables of the struct
available to static functions (in public of this class).

Aren't they? Since PData is a member, it should be available, and since
its members are public (by default), they should be available as well.
> if I need to
make the struct static also or just need the struct static but not the
members I really dont care. The ultimate goal here is to 1.) get
something to work 2.) Get a better understanding of how C++ does things
(such as static structs or static members of structs)

Read FAQ 5.8.

V
 
J

Jay Nabonne

This is probably an easy answer but since I am fairly new to C++ for
some reason I can't see it :-( Any help would be appreciated
:)

I have a class:

class AClass
{
public:
.
. (some functions)
private:
struct PData
{
static int aValue;
static int bValue;
}
}

I am clueless as to how to format the definition. Everything I have
tried up till now has been flagged by the compiler
Please Help

In a CPP file:

int AClass::pData::aValue;
int AClass::pData::bValue;

You can also initialize them:

int AClass::pData::aValue = 42;
int AClass::pData::bValue = 314;

- Jay
 
S

SteveM

Thanks Jay,

That is exactly what I was needing :)

Also sorry to Victor for the unclear way in which I presented my
problem :-(
I will try to be more clear in the future. I did miss some things in my
attempt at
explaining the problem. sorry

-Steve :)
 

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
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top