how to initialize const?
Author |
Message |
greenapplesodaex
![](http://img.photobucket.com/albums/v235/greenapplesodaex/big.jpg)
|
Posted: Tue Nov 14, 2006 10:52 pm Post subject: how to initialize const? |
|
|
code: |
Event.h
Event(string des, string loc, Date s, Date e);
string description;
string location;
const Date start; //<-
const Date end; //<-
|
code: |
Event.cc
Event::Event(string des, string loc, Date s, Date e):start(s),end(e)
{ description= des;
location = loc;
}
|
everything works up to here... like when i compile, it doesnt scream at me
but in another class, where i use this class
code: |
//Calendar.cc
const Date tsd(sd);
const Date ted(ed);
Event tempEvent(des,loc,tsd,ted);
|
then i got this compile error
Calendar.cc:43: instantiated from here
/fsys/.software/arch/gcc-3.4.2/bin/../lib/gcc/sparc-sun-solaris2.8/3.4.2/../../../../include/c++/3.4.2/bits/vector.tcc:238: error: non-static const member `const Date Event::start', can't use default assignment operator
/fsys/.software/arch/gcc-3.4.2/bin/../lib/gcc/sparc-sun-solaris2.8/3.4.2/../../../../include/c++/3.4.2/bits/vector.tcc:238: error: non-static const member `const Date Event::end', can't use default assignment operator
can anyone help please? im going crazy over this right now |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
Posted: Tue Nov 14, 2006 10:57 pm Post subject: (No subject) |
|
|
try having const constructor and const parameters |
|
|
|
|
![](images/spacer.gif) |
greenapplesodaex
![](http://img.photobucket.com/albums/v235/greenapplesodaex/big.jpg)
|
Posted: Tue Nov 14, 2006 11:13 pm Post subject: (No subject) |
|
|
sorry that didnt work.... i did, however, now made them all private and use a getter... :s and it's not giveing error anymore
thanx anyways |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Wed Nov 15, 2006 10:03 am Post subject: (No subject) |
|
|
Please show all of your code. |
|
|
|
|
![](images/spacer.gif) |
|
|