0

I have a class template which defines a type inside it:

#include <boost/array.hpp>

template <typename T, int N>
class MyFunct {
public:
  typedef boost::array<T,N> FArray;
  MyFunct();
};

Now I have another class template. The thing that makes this class particular is that it is supposed to work only with types that define, inside of them, a type called FArray. Do not ask why please, there is a reason for this.

template <typename F>
class MyClass {
public:
  MyClass() {
    F::FArray a = F::FArray();
  }
};

And I use this:

int main(int argc, char** argv) {
  MyClass< MyFunct<double,10> > m;
}

When I have this situation the compiler gets mad telling me that double has no member called FArray. What's happening?

Dmitry Ledentsov
  • 3,490
  • 16
  • 27
Andry
  • 14,281
  • 23
  • 124
  • 216
  • I voted for close... I searched among questions but did not find the one reported now... I am sorry. – Andry Sep 04 '13 at 11:48

2 Answers2

2

You need to use typename here:

typename F::FArray a = typename F::Array();
juanchopanza
  • 210,243
  • 27
  • 363
  • 452
1

Sloppy coding. Plus, g++ 4.7 says explicitly:

test.cpp:14:9: error: need ‘typename’ before ‘F:: FArray’ because ‘F’ is a dependent scope

And the following compiles OK.

#include <boost/array.hpp>

template <typename T, int N>
class MyFunct {
    public:
          typedef boost::array<T,N> FArray;
              MyFunct();
};

template <typename F>
class MyClass {
    public:
        MyClass() {
            typename F::FArray a = typename F::FArray();
        }
};

int main(int argc, char** argv) {
      MyClass< MyFunct<double, 2> > m;
}
rishta
  • 921
  • 1
  • 10
  • 24