Template Inheritance Bug ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I tried to compile the code below.
The compiler couldn't find the method 'Set()' in the class A.
Without the template method 'Set()' in the class B everything is OK. 

Could you explane,please, if it is a compiler bug or just the compiler feature.

Best regards,
Yury


GCC Vertion.
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518

The compiler messages.
./exaple.cpp: In function `int main()':
./exaple.cpp:76: error: no matching function for call to `B<WHY>::Set(long double, long double)'


template <typename EntityName>
class A
{
	public :
	  A(){}
	  A(long double v01, long double v02): _01(v01), _02(v02) {}
	  ~A(){}
	
template <typename Name>
	void Set(Name v01, Name v02)
	{
		_01= v01 ;
		_02= v02 ;
	}
	
template <typename Name>
	friend bool operator> (Name const &s01, Name const &s02)
	{
		return (s01._01-s02._01) > (s02._02-s01._02) ;
	}

	long double Get01(void) const { return  _01;}
	long double Get02(void) const { return  _02;}

	
	private :
	 A(EntityName const &instance) ;
	
	 long double _01 ;
	 long double _02 ;
} ;

template <typename EntityName>
class B : public A<EntityName>
{
	public :
	  B(){}
	  B(long double v01, long double v02): A<EntityName>(v01, v02) {}
	  ~B(){}

///////////////////////////////////////////////////////////////////	
template <typename FormatName>
      void Set(FormatName const &instance)
///////////////////////////////////////////////////////////////////
      {
		  this->Set(instance.GetS01(), instance.GetS02()) ;
	  }
	
} ;

class WHY ;
typedef B<WHY> TYPICAL_SAMPLE ;

#include <iostream>
#include <iomanip>

using namespace std ;

int main (void)
{
	TYPICAL_SAMPLE a(3.14L, 2.72L) ;
	TYPICAL_SAMPLE b(8.31L, 0.58L) ;
	
	cout << "\na " << a.Get01() << ' ' << a.Get02()
		 << "\nb " << b.Get01() << ' ' << b.Get02()
		 << "\na > b " << (a > b)
		 << endl ;
	
	b.Set(1.62L, 8.31L) ;
	
	cout << "\na " << a.Get01() << ' ' << a.Get02()
		 << "\nb " << b.Get01() << ' ' << b.Get02()
		 << "\na > b " << (a > b)
		 << endl ;
	
	return 0 ;
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux