This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Strange behavior with templates and G++


Hi,
While compiling the following code, I got an error :


template<class C> class Super
{
public:
	Super(void) {}
	void Test(C*) {}
};

class A
{
public:
	A(void) {}
};

class A1 : public A
{
public:
	A1(void) : A() {}
};

class A2 : public A
{
public:
	A2(void) : A() {}
};

class Super2 : public Super<A1>, public Super<A2>
{
public:
	Super2(void) {}
};

void Test(void)
{
	Super2 T;
	A1* ptr;
	T.Test(ptr);
}


The compiler gives me the following error for the Test() function:
	error: request for member âTestâ is ambiguous
	error: candidates are:	void Super<C>::Test(C*) [with C = A2]
	error:				void Super<C>::Test(C*) [with C = A1]
But here the call refers clearly to the second method. The error still appears 
if A1 and A2 do not inherit from a same root class. If I replace the code with 
an explicit call it works:
	T.Super<A1>::Test(ptr)
But this make the code less cleaner. 

Is this a problem related to a misunderstood concept from me, a wrong 
implementation or a technical problem of g++ ?

Thanks.
-- 

Dr. Ir. Pascal Francq
BELGIUM

Attachment: signature.asc
Description: This is a digitally signed message part.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]