Computer Science Canada

how to initialize const?

Author:  greenapplesodaex [ 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

Author:  bugzpodder [ Tue Nov 14, 2006 10:57 pm ]
Post subject: 

try having const constructor and const parameters

Author:  greenapplesodaex [ Tue Nov 14, 2006 11:13 pm ]
Post 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

Author:  wtd [ Wed Nov 15, 2006 10:03 am ]
Post subject: 

Please show all of your code.


: