Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > structure and constant memebers

Reply
Thread Tools

structure and constant memebers

 
 
ravinder thakur
Guest
Posts: n/a
 
      10-04-2005
hi all experts,

i have a structure with the constant memebers such as one given below:

typedef struct {
const int cbcode;
int cberror;

} xtsetplatestaterec;

now in my function i want to create a stack based object for the same:

void CreateObjectAndUseIt{
xtsetplatestaterec plate;
xtsetplatestaterec plate2 = {0 , 0};

}

now this function is giving the compilation errors while compiling on
vc++ 6.0 since the
cbcode memeber is a constant. the error is

error C2512: 'xtsetbleedvaluesrec' : no appropriate default constructor
available
error C2552: 'tmpsetplatestaterec' : non-aggregates cannot be
initialized with initializer list

can anybody plz explain me what could be done to create instances of
these objects on stack ???



strangly this code compiles in the c framework and not in the c++
framework.
is there some difference in the way interpertation of const members in
structures in c
and c++ language??? and if yes then is there any work around to the
problem other than removing the const from the strctures.




thanks
rt

 
Reply With Quote
 
 
 
 
Milind
Guest
Posts: n/a
 
      10-04-2005
> i have a structure with the constant memebers such as one given below:
>
> typedef struct {
> const int cbcode;
> int cberror;
>
> } xtsetplatestaterec;


Constant cannot be assigned can only be initialized.
so simple thing would be :


struct xtsetplatestaterec {
const int cbcode;
int cberror;
xtsetplatestaterec (int something = 0)
: cbcode (something ) {}

}; // we dont need the typedef!!

> void CreateObjectAndUseIt{
> xtsetplatestaterec plate;

this will work.
> xtsetplatestaterec plate2 = {0 , 0};


what are you trying to init ?? an agregate??
> }
>
>

hth
~M

 
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
pointers to constant characters and constant pointers to characters sam_cit@yahoo.co.in C Programming 4 12-14-2006 11:10 PM
structure and constant memebers ravinderthakur@gmail.com C Programming 13 10-26-2005 10:11 AM
can I use a pointer to step through memebers of structures? G Patel C Programming 8 02-07-2005 08:49 PM
"Non-constant" constant can't be used as template argument Martin Magnusson C++ 2 10-08-2004 08:41 AM
Understanding How To Use #ifdef Constant #define Constant Sequence In Multible Files Christopher M. Lusardi C++ 1 09-02-2004 07:43 AM



Advertisments