| | |
Error while compilation in the args of the function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 1
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&)
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?
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)
class RMStore { string command; string result; string error; bool status; public: RMStore(string comm = ""); inline string getCommand(); inline string getResult(); bool executeCommand(); }; RMStore::RMStore(string comm):command(comm) { result = ""; error = ""; } string RMServer::getData() { return data; } int main() { string command; command = "ls -l /usr/local/dataware | grep ^l"; RMServer *server = new RMServer(); if(server->openConn() > 0) { while(server->acceptConn() > 0) { if(server->recvData() > 0) { RMStore *R = new RMStore(server->getData()); //RMStore *R = new RMStore(command); R->executeCommand(); server->sendData(R->getResult()); //server->sendData(command); delete R; } } } }
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?
Visual C++ 9.0 compiler resolves this situation. Obvious workaround with your compiler: define explicitly default RMStore constructor (an all others):
Use explicit keyword in that case (in constructors with the single parameter). Without explicit the
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.
c++ Syntax (Toggle Plain Text)
class RMStore { public: // Place public part at the beginning RMStore():status(false){} // You forgot initialize status member explicit RMStore(const char* pcmd): command(p?p:""),status(false) {} explicit RMStore(const std::string& cmd): command(cmd),status(false) {} const std::string& getCommand() const { return command; } ... private: std::string command; std::string result; // No need to initialize empty string members // explicitly: string default constructors do it. ... };
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.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: How do I make vectors of an already vectorized thing?
- Next Thread: Manipulators
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return string strings struct studio system template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






