C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem mit bind bei Referenz-Argument

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Jan Boehme
Guest





PostPosted: Fri Mar 30, 2007 9:00 pm    Post subject: Problem mit bind bei Referenz-Argument Reply with quote



Hallo,
in nachfolgendem Code soll ueber for_each die Methode von Objekten
aufgerufen werden, die als Argument eine Referenz auf ein Objekt bekommen.

Aendere ich das Argument auf eine Kopie von std::string, geht es wie
gewuenscht, die nachfolgende Version ergibt jedoch folgenden
Kompilierfehler unter gcc4:
25: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h:435:
error: forming reference to reference type ‘std::string&’

Kann mir jemand Rat geben?
Danke, jan.

<code>

#include <list>
#include <iostream>
#include <functional>
#include <string>

class A
{
int a_;
public:
A( const int &_a ) : a_(_a) { }
std::string& foo( std::string &s) {
std::cout << s << ": " << a_ << std::endl;
return s;
}
};

int main()
{
std::list<A> la;
la.push_back(A(1));
la.push_back(A(2));
la.push_back(A(3));

std::string s("content");
std::for_each( la.begin(), la.end(),
std::bind2nd( std::mem_fun_ref(&A::foo), s ) );
}

</code>
Back to top
Thomas Maeder
Guest





PostPosted: Sat Mar 31, 2007 2:10 am    Post subject: Re: Problem mit bind bei Referenz-Argument Reply with quote



Jan Boehme <aiscape (AT) hotmail (DOT) com> writes:

Quote:
in nachfolgendem Code soll ueber for_each die Methode von Objekten
aufgerufen werden, die als Argument eine Referenz auf ein Objekt
bekommen.

Aendere ich das Argument auf eine Kopie von std::string, geht es wie
gewuenscht, die nachfolgende Version ergibt jedoch folgenden
Kompilierfehler unter gcc4:
25: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h:435:
error: forming reference to reference type std::string&

Kann mir jemand Rat geben?

Ja.

Verwende boost::bind (siehe http://www.boost.org/).
Back to top
Jan Boehme
Guest





PostPosted: Tue Apr 03, 2007 3:07 pm    Post subject: Re: Problem mit bind bei Referenz-Argument Reply with quote



Thomas Maeder wrote:
Quote:
Ja.

Verwende boost::bind (siehe http://www.boost.org/).

Danke, damit läuft's.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.