static struct initialization in a Class:: -- not my struct

Discussion in 'C++' started by christian.bongiorno@gmail.com, Sep 20, 2006.

  1. Guest

    I am would love to be able to initialize a struct statically in my
    class, but the compiler seems to throw a fit when I do. I have
    something like

    // in h file
    class MyClass {


    private:
    static CK_INFO aStruct;
    };

    // in .cpp file
    // yes, I know the strings must be blank padded
    MyClass::aStruct = {{1,0},"christian",0,"Whatever",{2,0}};

    The struct looks like this:

    typedef struct CK_INFO {
    CK_VERSION cryptokiVersion; /* Cryptoki interface version
    number */
    CK_CHAR manufacturerID[32]; /* blank padded */
    CK_FLAGS flags; /* must be zero */

    /* libraryDescription and libraryVersion are new for v2.0 */
    CK_CHAR libraryDescription[32]; /* blank padded */
    CK_VERSION libraryVersion; /* version of library */
    } CK_INFO;

    error C2501: 'MyClass::info' : missing storage-class or type
    specifiers
    error C2371: 'info' : redefinition; different basic types

    I know this is propably an easy question, I am just not that familiar
    with static initializing in C++
     
    , Sep 20, 2006
    #1
    1. Advertising

  2. S S Guest

    wrote:
    > I am would love to be able to initialize a struct statically in my
    > class, but the compiler seems to throw a fit when I do. I have
    > something like
    >
    > // in h file
    > class MyClass {
    >
    >
    > private:
    > static CK_INFO aStruct;
    > };
    >
    > // in .cpp file
    > // yes, I know the strings must be blank padded
    > MyClass::aStruct = {{1,0},"christian",0,"Whatever",{2,0}};
    >
    > The struct looks like this:
    >
    > typedef struct CK_INFO {
    > CK_VERSION cryptokiVersion; /* Cryptoki interface version
    > number */
    > CK_CHAR manufacturerID[32]; /* blank padded */
    > CK_FLAGS flags; /* must be zero */
    >
    > /* libraryDescription and libraryVersion are new for v2.0 */
    > CK_CHAR libraryDescription[32]; /* blank padded */
    > CK_VERSION libraryVersion; /* version of library */
    > } CK_INFO;


    Try removing above CK_INFO

    >
    > error C2501: 'MyClass::info' : missing storage-class or type
    > specifiers
    > error C2371: 'info' : redefinition; different basic types
    >
    > I know this is propably an easy question, I am just not that familiar
    > with static initializing in C++
     
    S S, Sep 20, 2006
    #2
    1. Advertising

  3. David Harmon Guest

    On 20 Sep 2006 11:06:33 -0700 in comp.lang.c++,
    wrote,
    > static CK_INFO aStruct;
    >};
    >
    >// in .cpp file
    >// yes, I know the strings must be blank padded
    >MyClass::aStruct = {{1,0},"christian",0,"Whatever",{2,0}};


    CK_INFO MyClass::aStruct = {{1,0},"christian",0,"Whatever",{2,0}};
    ^^^^^^^
     
    David Harmon, Sep 20, 2006
    #3
    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. SaravanaKumar
    Replies:
    6
    Views:
    9,514
    Tony Morris
    Oct 19, 2004
  2. Michael Klatt
    Replies:
    6
    Views:
    2,713
    Jesper Madsen
    Nov 18, 2003
  3. DanielBradley
    Replies:
    3
    Views:
    14,988
    Dave Moore
    Jun 2, 2004
  4. bugbear
    Replies:
    4
    Views:
    466
    bugbear
    Aug 23, 2006
  5. Robin
    Replies:
    0
    Views:
    439
    Robin
    Jun 6, 2007
Loading...

Share This Page