Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   static struct initialization in a Class:: -- not my struct (http://www.velocityreviews.com/forums/t457043-static-struct-initialization-in-a-class-not-my-struct.html)

christian.bongiorno@gmail.com 09-20-2006 06:06 PM

static struct initialization in a Class:: -- not my struct
 
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++


S S 09-20-2006 06:29 PM

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

christian.bongiorno@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++



David Harmon 09-20-2006 06:53 PM

Re: static struct initialization in a Class:: -- not my struct
 
On 20 Sep 2006 11:06:33 -0700 in comp.lang.c++,
christian.bongiorno@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}};
^^^^^^^



All times are GMT. The time now is 12:25 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57