Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re[2]: GCC 3.3 template compile error?




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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden

References: 
 >GCC 3.3 template compile error? (From: "Tim Conkling" <email@hidden>)
 >Re: GCC 3.3 template compile error? (From: "Clark Cox" <email@hidden>)
 >Re: GCC 3.3 template compile error? (From: "Tim Conkling" <email@hidden>)
 >Re[2]: GCC 3.3 template compile error? (From: Peter Mulholland <email@hidden>)
 >Re: Re[2]: GCC 3.3 template compile error? (From: eric b <email@hidden>)
 >Re: Re[2]: GCC 3.3 template compile error? (From: Martin-Gilles Lavoie <email@hidden>)
 >Re: Re[2]: GCC 3.3 template compile error? (From: Steve Checkoway <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.