| | |
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 |
* ansi api array arrays binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database directory dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez grade graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o inches include infiniteloop input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






