Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to initialize const?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
greenapplesodaex




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
bugzpodder




PostPosted: Tue Nov 14, 2006 10:57 pm   Post subject: (No subject)

try having const constructor and const parameters
greenapplesodaex




PostPosted: 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
wtd




PostPosted: Wed Nov 15, 2006 10:03 am   Post subject: (No subject)

Please show all of your code.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: