Problem with functions that allow inner classes of template classes

I have a problem with inner classes in class templates. I have a template class (say:) Matrix<T>and a subclass (say:) Matrix<T>::Row. Now I want to write a function that works with instances of a subclass (say:) negate(Matrix<T>::Row &). I tried to declare a function using template<class T> negate(typename Matrix<T>::Row &), but when I try to use it, the compiler tells me that it cannot find a match.

Here is an abstract example:

template<class T>
class A
{
public:
    class B
    {
    };
};

template<class T>
void x(typename A<T>::B &)
{
}

int main()
{
    A<int>::B b;
    x(b); // doesn't work: Error: Could not find a match
          // for x<T>(A<int>::B) needed in main().
    x<int>(b); // works fine
}

Why can't the compiler find xin the first case? Is there a way to change this so that it works (without explicitly specifying a type int)?

( , x template<class T, class S> void x(typename A<T>::B &, const S &);, , .)

g++ 4.4.3, g++ 4.5.2 Sun Studio 5.9, . - !

+4
3

? :

struct A { typedef int T; };
struct B { typedef int T; };

template <typename S> void foo(typename S::T);

, int x; foo(x);, .

, , , . , , .

+3

. .

, A :

template <>
struct A<SomeType>
{
    typedef std::map <double, double> B;
};

, B, typedef std::map<double,double>.

, SomeType, , A<SomeType>::B std::map<double, double>?

, , :

template <>
struct A<SomeOtherType>
{
    typedef std::map <double, double> B;
};

B .

, A<T>::B is std::map<double,double>, , T? SomeType? SomeOtherType?

+2

All Articles