• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Re[2]: GCC 3.3 template compile error?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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>)

  • Prev by Date: Re: GDB handing when step into
  • Next by Date: Re: Three-way merge program
  • Previous by thread: Re: Re[2]: GCC 3.3 template compile error?
  • Next by thread: Have dylib, want to preserve drag-install
  • Index(es):
    • Date
    • Thread