| | |
error in copy constructor
Thread Solved
![]() |
Potion of my code:
Pretty straighforward. But I keep got error:
error: passing `const UserCommand' as `this' argument of `std::string UserCommand::getHandle()' discards qualifiers
I am using gcc under redhat, anyone can help me on this? thanks in advance.
C Syntax (Toggle Plain Text)
class UserCommand{ string cHandle; //definition of command int numPara; vector<int> cPara; //parameter of command public: UserCommand(string ucData); //copy constructor UserCommand(const UserCommand& uc); inline const string getHandle(){return cHandle;}; inline const int getPara(int i){return cPara.at(i);}; inline const int getNumPara(){return numPara;}; //overload operator = here inline UserCommand operator=(UserCommand& uc); }; // //... UserCommand::UserCommand(const UserCommand& uc){ cHandle=uc.getHandle(); numPara=uc.getNumPara(); for(int i=0;i<numPara;i++) cPara[i]=uc.getPara(i); }
Pretty straighforward. But I keep got error:
error: passing `const UserCommand' as `this' argument of `std::string UserCommand::getHandle()' discards qualifiers
I am using gcc under redhat, anyone can help me on this? thanks in advance.
inline const string getHandle(){return cHandle;}; inline const int getPara(int i){return cPara.at(i);}; inline const int getNumPara(){return numPara;};
inline string getHandle() const { return cHandle; } inline int getPara(int i) const { return cPara.at(i); } inline int getNumPara() const { return numPara; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Copy constructor in derived class (C)
- copy constructor & assignment operator overload problems (C++)
- (C++) Writing a Copy Constructor?!? (C++)
- copy constructor problem (C++)
- need the usage of Copy Constructor (C++)
Other Threads in the C Forum
- Previous Thread: #include <GL/glut.h>
- Next Thread: Program for gauge monitoring
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






