Ashot
Ashot

Reputation: 10959

expected constructor, destructor, or type conversion before "A"

template <typename T>
class A {
    class B {
        typedef int INT;
        INT func(double e) {
            return INT(e * 3.6);
        }
    };
};

My problem is to remove the definition of func function from class declaration. This is the simplified case of my program. The compiler complains of typedef.

Here is my try:

template <typename T>
A<T>::B::INT A<T>::B::func(double e) {
    return INT(e * 3.6);
}

The compiler error is main.cpp:14: error: expected constructor, destructor, or type conversion before "A".

Upvotes: 0

Views: 634

Answers (1)

kennytm
kennytm

Reputation: 523274

g++ 4.7 pointed to the problem directly:

$ g++ 3.cpp
3.cpp:12:1: error: need 'typename' before 'A<T>::B::INT' because 'A<T>::B' is a dependent scope

So:

    template <typename T>
    typename A<T>::B::INT A<T>::B::func(double e) {
//  ^^^^^^^^
        return INT(e * 3.6);
    }

Upvotes: 6

Related Questions