0

Potion of my code:

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.

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by alone2005
0
inline const string getHandle(){return cHandle;};
	inline const int getPara(int i){return cPara.at(i);};
	inline const int getNumPara(){return numPara;};

I believe it's telling you it would prefer that the this pointer be const. (And function definitions don't end with a semicolon.)

inline string getHandle() const { return cHandle; }
   inline int getPara(int i) const { return cPara.at(i); }
   inline int getNumPara()   const { return numPara; }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.