Skip to main content
GameDev.net gamedev.net
🔒 Locked

More STL Compiler nonsense

Started by Shannon Barber Apr 2, 2002 at 10:54 AM 7 replies 900+ views
Original Post
Shannon Barber
Shannon Barber
[qutoe] c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(303): error C2529: ''_Right'' : reference to reference is illegal I thought they were going to change it so that a reference to a reference yields the same reference. Otherwise, you can''t use any binders (and probably not most other adaptors) with functors that take references!
Socket::tcpPacket packet;
//...
std::for_each(this->vConnectedSockets.begin(),
              this->vConnectedSockets.end(),
              std::bind2nd(std::mem_fun(&tyRecvSocket::Send), packet));
 
Is my only STL friendly option to use pointers, and never use references? Magmai Kai Holmlor "Oh, like you''ve never written buggy code" - Lee
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Stoffel
Stoffel
Don''t you need mem_fun_ref instead? I''ve been able to do this myself (not with bind2nd, but with a void member function). Can you throw up the Socket::Send declaration?
TangentZ
TangentZ

Actually, "reference-to-reference" is currently disallowed
by Standard C++. It is not VC.NET''s fault. No compliant
compiler will take reference-to-reference. There is a
plan to rectify this "defect" in the next revision of
the C++ Standard.


I''ve got what it takes to be the Best of the Best, any questions?
神はサイコロを振らない!
SabreMan
SabreMan
quote:
Original post by Stoffel
Don''t you need mem_fun_ref instead?

Yup. mem_fun is for calling a function when you have a pointer to object.
quote:
Original post by Stoffel
Actually, "reference-to-reference" is currently disallowed
by Standard C++.

Perhaps you can point out where Magmai is forming a reference-to-reference in his code?
Shannon Barber
Shannon Barber
quote:
Original post by Stoffel
Don''t you need mem_fun_ref instead? I''ve been able to do this myself (not with bind2nd, but with a void member function). Can you throw up the Socket::Send declaration?



Socket::Error
template
class tcpDataSocket::Send(const tcpPacket& packet)

tyRecvSocket is a typedef of an actual templated class (a server receive scoket flavor of tcpDataSocket)

IIRC, mem_fun_ref is when the object you want to invoke the method using an object reference, obj.Method as opposed to obj->Method. If your container has pointers in it, you use mem_fun, but if it has actual instances in it, you use mem_fun_ref.
At any rate, I automatically tried the _ref flavor, when mem_fun didn''t compile, to no avail. The problem is that Send takes a reference, and bind2nd takes a reference, and bind2nd tries to stuff its reference into the packet& hole of the mem_functor''ed Send.

Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Stoffel
Stoffel
Ah, I misunderstood. You''re right, you''re screwed. =)
Void
Void
Boost has ref,cref, and bind functors which perhaps may solve the problem.
SabreMan
SabreMan
Absolutely! Boost and Loki both have library features to solve this problem, but I can''t tell you which features to look for off the top of my head.
Gorg
Gorg
This is from Andrei Alexandrescu's code gard


  

template <class T>
class RefHolder
{
T& ref_;
public:
RefHolder(T& ref) : ref_(ref) {}
operator T& () const
{
return ref_;
}
};
template <class T>
inline RefHolder<T> ByRef(T& t)
{
return RefHolder<T>(t);
}



Your problem is solved

[edited by - Gorg on April 3, 2002 5:10:34 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.