943,896 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 412
  • C++ RSS
Dec 19th, 2008
0

Error while compilation in the args of the function

Expand Post »
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&)



C++ Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
sweeya is offline Offline
8 posts
since Nov 2008
Dec 19th, 2008
0

Re: Error while compilation in the args of the function

Visual C++ 9.0 compiler resolves this situation. Obvious workaround with your compiler: define explicitly default RMStore constructor (an all others):
c++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How do I make vectors of an already vectorized thing?
Next Thread in C++ Forum Timeline: Manipulators





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC