LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2011, 08:45 PM   #1
fsshl
Member
 
Registered: Jan 2002
Distribution: Ubuntu10.04
Posts: 49

Rep: Reputation: 1
No match for 'operator<<' in '((HttpRequest*


Dear advanced c/g++ programers:

I have a simple program from book C++ cookbook, page 291, 8.3, Using
Constructors and Destructors to manage
resources (or RAII), but it can not get compiled in my g++
------------------------------------------------------------------------------------------------
// Example 8-3. Using constructors and destructors
#include <iostream>
#include <string>
using namespace std;
class Socket {
public:
Socket(const string& hostname) {}
};
class HttpRequest {
public:
HttpRequest (const string& hostname) :
sock_(new Socket(hostname)) {}
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");
}
------------------------------------------------------------------------------------------------------------------------
my test compile fail as
----------------------------------
eric@eric-laptop:~/cppcookbook/ch8$ g++ Example8-3.cpp
Example8-3.cpp: In member function ‘void
HttpRequest::send(std::string)’:
Example8-3.cpp:13:39: error: no match for ‘operator<<’ in
‘((HttpRequest*)this)->HttpRequest::sock_ << soapMsg’
-------------------------------------------------------------
on both g++ 4.3.4 and 4.5.2
you can get its source code from
http://examples.oreilly.com/9780596007614/
to test by yourself

looking and thanks your help a lot in advance, Eric
 
Old 07-14-2011, 01:57 PM   #2
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by fsshl View Post
Dear advanced c/g++ programers:
This code won't compile. Perhaps it wasn't meant to be compiled at all and is simply an illustration.

This:
Code:
  void send(string soapMsg) {sock_ << soapMsg; }
Requires operator<< for Socket class, which isn't present.

Last edited by SigTerm; 07-14-2011 at 02:01 PM.
 
Old 07-14-2011, 07:07 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Is the Socket class defined more completely somewhere else in the book? Even if so, sock_ is a pointer so it would either need to be *sock_ << ... or there would need to be operator << (Socket*, string) defined outside of a class. I'm wondering if you need a new book.
Kevin Barry
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++ Operator Overloading Within an Already Overloaded Operator mirlin510 Programming 8 04-17-2011 12:02 PM
[SOLVED] Match datetime by the minute (not an exact match by the second) [mysql] hattori.hanzo Programming 1 10-21-2010 05:43 PM
php/HttpRequest/https: A TLS packet with unexpected length was received eantoranz Programming 1 05-30-2010 06:40 AM
save client httpRequest method. Tareq85 Programming 2 06-10-2008 10:28 AM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration