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

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

P: n/a
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 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
S S

ch*****************@gmail.com 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++
Sep 20 '06 #2

P: n/a
On 20 Sep 2006 11:06:33 -0700 in comp.lang.c++,
ch*****************@gmail.com 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}};
^^^^^^^

Sep 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.