Need Help with static struct class definition

Discussion in 'C++' started by SteveM, Sep 23, 2005.

  1. SteveM

    SteveM Guest

    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 :)
     
    SteveM, Sep 23, 2005
    #1
    1. Advertising

  2. SteveM wrote:
    > 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
     
    Victor Bazarov, Sep 23, 2005
    #2
    1. Advertising

  3. SteveM

    Jay Nabonne Guest

    On Fri, 23 Sep 2005 09:20:58 -0700, SteveM wrote:

    > 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
     
    Jay Nabonne, Sep 23, 2005
    #3
  4. SteveM

    SteveM Guest

    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 :)
     
    SteveM, Sep 23, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A.M
    Replies:
    5
    Views:
    843
  2. Jianli Shen
    Replies:
    1
    Views:
    594
    Victor Bazarov
    Mar 13, 2005
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,392
    Chris Fogelklou
    Apr 20, 2004
  4. Ark
    Replies:
    1
    Views:
    421
    Chris Torek
    Aug 7, 2004
  5. Replies:
    2
    Views:
    740
    David Harmon
    Sep 20, 2006
Loading...

Share This Page