Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static struct initialization in a Class:: -- not my struct

Reply
Thread Tools

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

 
 
christian.bongiorno@gmail.com
Guest
Posts: n/a
 
      09-20-2006
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++

 
Reply With Quote
 
 
 
 
S S
Guest
Posts: n/a
 
      09-20-2006

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++


 
Reply With Quote
 
 
 
 
David Harmon
Guest
Posts: n/a
 
      09-20-2006
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}};
^^^^^^^

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Initialization of non-integral type in initialization list anongroupaccount@googlemail.com C++ 6 12-11-2005 09:51 PM
Initialization via ctor vs. initialization via assignment Matthias Kaeppler C++ 2 07-18-2005 04:25 PM
Default Initialization Vs. Value Initialization JKop C++ 10 09-22-2004 07:26 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments
 



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