Re: No match for 'operator<<' in '((HttpRequest*
Post your code and errors.
--
Ian Collins
--------------------------------------------------------------------
If I tried your fist suggestion
---------------------------------
// Example 8-3. Using constructors and destructors
#include <iostream>
#include <string>
using namespace std;
class Socket {
public:
Socket(const string& hostname) {}
// ostream & operator<<(const std::string&) {}
};
class HttpRequest : public Socket {
public:
HttpRequest (const string& hostname) :
sock_(new Socket(hostname)) {}
ostream & operator<<( Socket*, const std::string& ) {}
void send(string soapMsg) {sock_ << soapMsg; }
~HttpRequest () {delete sock_;}
private:
Socket* sock_;
};
void sendMyData(string soapMsg, string host) {
HttpRequest req(host);
req.send(soapMsg);
// Nothing to do here, because when req goes out of scope
// everything is cleaned up.
}
int main() {
string s = "xml";
sendMyData(s, "www.oreilly.com");
}
---------------------------------------------------------------------------=
----
compile result is
------------------
eric@eric-laptop:~/cppcookbook/ch8$ g++ Example8-3.cpp
Example8-3.cpp:16:53: error: =91std::ostream&
HttpRequest::operator<<(Socket*, const std::string&)' must take
exactly one argument
Example8-3.cpp: In constructor =91HttpRequest::HttpRequest(const
std::string&)':
Example8-3.cpp:14:32: error: no matching function for call to
=91Socket::Socket()'
Example8-3.cpp:7:4: note: candidates are: Socket::Socket(const
std::string&)
Example8-3.cpp:5:14: note: Socket::Socket(const
Socket&)
Example8-3.cpp: In member function =91void
HttpRequest::send(std::string)':
Example8-3.cpp:18:39: error: no match for =91operator<<' in
=91((HttpRequest*)this)->HttpRequest::sock_ << soapMsg'
---------------------------------------------------------------------------=
---------------------------------------
If I tried my other design, put opearator << in class Socket
---------------------------------------------------
// Example 8-3. Using constructors and destructors
#include <iostream>
#include <string>
using namespace std;
class Socket {
public:
Socket(const string& hostname) {}
ostream & operator<<(const std::string&) {}
};
class HttpRequest: public Socket {
public:
HttpRequest (const string& hostname) :
sock_(new Socket(hostname)) {}
// ostream & operator<<( Socket*, const std::string& ) {}
void send(string soapMsg) {sock_ << soapMsg; }
~HttpRequest () {delete sock_;}
private:
Socket* sock_;
};
void sendMyData(string soapMsg, string host) {
HttpRequest req(host);
req.send(soapMsg);
// Nothing to do here, because when req goes out of scope
// everything is cleaned up.
}
int main() {
string s = "xml";
sendMyData(s, "www.oreilly.com");
}
---------------------------------------------------------------------------=
----------------------
I get the following compiler error
----------------------------------
eric@eric-laptop:~/cppcookbook/ch8$ g++ Example8-3.cpp
Example8-3.cpp: In constructor =91HttpRequest::HttpRequest(const
std::string&)':
Example8-3.cpp:14:32: error: no matching function for call to
=91Socket::Socket()'
Example8-3.cpp:7:4: note: candidates are: Socket::Socket(const
std::string&)
Example8-3.cpp:5:14: note: Socket::Socket(const
Socket&)
Example8-3.cpp: In member function =91void
HttpRequest::send(std::string)':
Example8-3.cpp:18:39: error: no match for =91operator<<' in
=91((HttpRequest*)this)->HttpRequest::sock_ << soapMsg'
---------------------------------------------------------------------------=
--------------------------------------
hope that help any advanced c/g++ program to debug my(actually
author's) program
Thanks a lot in advance
Eric