Error while compilation in the args of the function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 8
Reputation: sweeya is an unknown quantity at this point 
Solved Threads: 1
sweeya sweeya is offline Offline
Newbie Poster

Error while compilation in the args of the function

 
0
  #1
Dec 19th, 2008
Hi,
I have given only some part of the code related to my problem. I have problem while compliation. I have the problem in the constructor of the class RMstore. i Get the following compilation error

rmremote_server.cpp: In function `int main()':
rmremote_server.cpp:196: error: no matching function for call to `RMStore::RMStore(std::string)'
rmremote_server.cpp:17: note: candidates are: RMStore::RMStore(const RMStore&)
rmremote_server.cpp:26: note: RMStore::RMStore(std::string&)



  1.  
  2. class RMStore
  3. {
  4. string command;
  5. string result;
  6. string error;
  7.  
  8. bool status;
  9.  
  10. public:
  11.  
  12. RMStore(string comm = "");
  13. inline string getCommand();
  14. inline string getResult();
  15. bool executeCommand();
  16. };
  17.  
  18. RMStore::RMStore(string comm):command(comm)
  19. {
  20. result = "";
  21. error = "";
  22. }
  23.  
  24.  
  25. string RMServer::getData()
  26. {
  27. return data;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. string command;
  34. command = "ls -l /usr/local/dataware | grep ^l";
  35.  
  36.  
  37. RMServer *server = new RMServer();
  38.  
  39. if(server->openConn() > 0)
  40. {
  41. while(server->acceptConn() > 0)
  42. {
  43. if(server->recvData() > 0)
  44. {
  45. RMStore *R = new RMStore(server->getData());
  46. //RMStore *R = new RMStore(command);
  47. R->executeCommand();
  48. server->sendData(R->getResult());
  49. //server->sendData(command);
  50. delete R;
  51. }
  52. }
  53. }
  54.  
  55. }

I was under the impression that, even tough we pass a string, the called function will take it in a ref and the compiler will not complain.


also if i use RMStore *R = new RMStore(command); instead of RMStore *R = new RMStore(server->getData()); i donn get any errors.

am i missing something here? please help?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Error while compilation in the args of the function

 
0
  #2
Dec 19th, 2008
Visual C++ 9.0 compiler resolves this situation. Obvious workaround with your compiler: define explicitly default RMStore constructor (an all others):
  1. class RMStore {
  2. public: // Place public part at the beginning
  3. RMStore():status(false){}
  4. // You forgot initialize status member
  5. explicit RMStore(const char* pcmd):
  6. command(p?p:""),status(false)
  7. {}
  8. explicit RMStore(const std::string& cmd):
  9. command(cmd),status(false)
  10. {}
  11. const std::string& getCommand() const {
  12. return command;
  13. }
  14. ...
  15. private:
  16. std::string command;
  17. std::string result;
  18. // No need to initialize empty string members
  19. // explicitly: string default constructors do it.
  20. ...
  21. };
Use explicit keyword in that case (in constructors with the single parameter). Without explicit the RMStore::RMStore(type) constructor defines implicit conversion from type to RMStore. As usually it's not a desired effect.

You declared member function prototypes as inline. It's a senseless declaration because:
1. Where is that member function body to substitute it inline?
2. All member function definitions (with bodies) in a class definition are inline by default.
Last edited by ArkM; Dec 19th, 2008 at 5:41 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC