473,473 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Sep 20 '06 #1
2 2815
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
1
by: Piotr Sawuk | last post by:
just a quick question out of curiosity: how to initialize const arrays? struct srat { long num; ulong den; srat(){} } struct collisions
1
by: Stephen Lamb | last post by:
Does anyone know if the standard has anything to say about how static fields that use other static fields in initialization behave? Pointers into the standard would be most appreciated. Thanks. ...
8
by: Robert A Riedel | last post by:
I have an application that requires a DLL and an executable that uses the DLL, both of which were implemented in Visual C++ using unmanged code. Both the executable and the DLL are linked with...
8
by: Markus Henschel | last post by:
Hello, this is a test case of something I just can't explain myself: ...
1
by: philwozza | last post by:
Hi I have a THREAD class that uses the static variable NextThreadID to store the id of the next thread to be created and a static Mutex to protect it. class THREAD { public: int Start(void);...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
5
by: desktop | last post by:
Why is this struct illegal: #include<iostream> struct debug { std::string d1 = "bob\n"; }; I get this error:
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.