Skip to main content
gamedev.net
🔒 Locked

GNU C++ compiler bug?

Started by kRogue 2 replies 650+ views
Original Post
kRogue
kRogue
ok is the following bad C++ code, or is it a GNU C++ compiler bug:

template<typename T>
class FunctionFactory
{
public:
 class Base;
 //more public goodies, some types need Base defined.
private:
  //private stuff
public:
  class Base
  {
  public:
     //functions
     ostream &Print(ostream &str) 
     {
            //call a cirtual method that modifies str
            return str;
     }
     //some virtual functions....
  };

//lots more junk...
};


template<typename T>
ostream &operator<<(ostream &ostr, FunctionFactory<T>::Base &obj)
{
  return obj.Print(ostr);
}


with the above g++ gives this error message:
Quote:
FunctionFactory.hpp:1779: error: ‘class FunctionFactory<T>::Base’ is not a type FunctionFactory.hpp: In function ‘std::ostream& operator<<(std::ostream&, int&)’: FunctionFactory.hpp:1781: error: request for member ‘Print’ in ‘obj’, which is of non-class type ‘int’ make: *** [FunctionFactory] Error 1
is this just a g++ bug in the way it implements templates, or is the above incorrect C++ code for which g++ barfs in its own creative way?
Close this Gamedev account, I have outgrown Gamedev.
ToohrVyk
ToohrVyk
Incorrect C++. You meant typename FunctionFactory<T>::Base &obj.
kRogue
kRogue
thnx, yep I forgot that bloody typename key word again when extracting a type from a template class...
Close this Gamedev account, I have outgrown Gamedev.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.