Re: Re[2]: GCC 3.3 template compile error?
Re: Re[2]: GCC 3.3 template compile error?
- Subject: Re: Re[2]: GCC 3.3 template compile error?
- From: Steve Checkoway <email@hidden>
- Date: Mon, 15 Oct 2007 19:42:41 -0700
On Oct 15, 2007, at 7:28 PM, Steve Checkoway wrote:
Can you give sample code exhibiting the problem?
Actually, I think I might know what you mean. Something like:
#include <list>
struct Base
{
template <typename T>
void erase( std::list<T> &l )
{
l.erase( l.begin(), l.end() );
}
};
struct Derived : public Base
{
std::list<int> gar() { return std::list<int>(); }
void foo()
{
// erase<int>( gar() ); // Error!
std::list<int> l = gar();
erase( l );
}
};
int main()
{
Derived d;
d.foo();
return 0;
}
If that's what you meant, then this isn't a compile error (and not
related to templates). It could be that the error message you get is
confusing you because it doesn't really tell you what the problem is.
This program exhibits the same error but is far simpler:
void foo( int &i ) { i = 0; }
int bar() { return 6; }
int main()
{
foo( bar() );
return 0;
}
The error message is much friendlier too.
foo2.cc: In function ‘int main()’:
foo2.cc:6: error: invalid initialization of non-const reference of
type ‘int&’ from a temporary of type ‘int’
foo2.cc:1: error: in passing argument 1 of ‘void foo(int&)’
The second line says it all.
Of course, if this isn't at all what you mean, then my apologies to
the list.
--
Steve Checkoway
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden