Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with templates and inheritance

Status
Not open for further replies.

globos

Programmer
Nov 8, 2000
260
0
0
FR
Hi,

Please try to compile this code :

Code:
template<class G, class H>
class Table
{
public:
  virtual const G& item (const H& k) const = 0;
};

template<class G>
class Indexable : public Table<G, int>
{
public:
  //virtual const G& item (const int& k) const = 0;
  virtual const G& i_th (int i) const
  { return item (i); }
};


int main ()
{ return 0; }

This simple source code compiles without any warning with Microsoft VC++6's compiler. With gcc 3.4.3 I get the errors :

test-gcc.cpp: In member function `virtual const G& Indexable<G>::i_th(int) const':
test-gcc.cpp:14: error: there are no arguments to `item' that depend on a template parameter, so a declaration of `item' must be available
test-gcc.cpp:14: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)


I can't understand why g++ is not happy with this code snippet. If you decomment the line in class Indexable(redeclaration of Table<G, int>::item()), then g++ can compile. What is going on?

--
Globos
 
It also compiles fine on VC++ 2005. Don't have a UNIX box available right now though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top