1

I have the following situation:

template <class A, typename B, typename C, class D>
class Base
{
    public:
       // ctor and virtual dtor
       // functions
       class Inner
       {
           //...
       };

    protected:
       // members
};

template <class E>
class Sub : public Base<std::string, float, double, E>
{
    public:
       // ctor and virtual dtor

       // functions using Inner class inherit from Base
};

While msvc compiles just fine (visual studio 2012 with ctp nov 2012 compiler), gcc (4.9.0 build from trunk) complains about every member used from Base and also about the inner class from Base.

I noticed that msvc is quite relaxed when it comes to templates, however i also need this code running and compiling under linux with gcc. So, where is the bogus code that msvc accepts but gcc not?

Michael Haidl
  • 5,384
  • 25
  • 43
  • 3
    It is probably a dependent name issue. You might need to specify `Base::theMethodName()` or `this->theMethodName()`. But you should include at least one line that causes an error. – juanchopanza Sep 12 '13 at 08:01
  • Please provide an [SSCCE](http://sscce.org). *A guess*: you'll probably need some `typename` – dyp Sep 12 '13 at 08:01
  • Did you try to compile your snippet with `g++ -c` and that did fail? Because it compiles fine in g++ 4.8 – nikolas Sep 12 '13 at 08:02

1 Answers1

2

The core problem is that names which don't depend on template parameters are looked up at declaration, not instantiation time. Use e.g. Base<std::string, float, double, E>::Inner instead of just Inner, or put a using declaration in your class: using Base<std::string, float, double, E>::Inner. This will make the names dependent and thus looked up at instantiation time.

For more info, search for "dependent name lookup."

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455