#algorithm.h
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <iostream>
using std::cin; using std::cout; using std::endl;
template <class T>
class A
{
struct B;
public:
A(){}
~A(){}
B get();
private:
struct B
{
T elem;
B():elem(0){}
};
};
#endif
#algorithm.cpp
#<span style="font-family: Arial, Helvetica, sans-serif;">include "algorithm.h"</span>
template <class T>
typename A<T>::B get()
{
return 0;
}
In class A, if I want to return type B from function get(), I have to declare type B before get() while I implement struct B later.
In "algorithm.cpp", a scope operator is enough, i.e. no need to write code like this:
typename A<T>::B A<T>::get()
Yet the keyword typename is a must.