开发者

generic programming in c++ and typedef inside a class

开发者 https://www.devze.com 2023-04-06 11:43 出处:网络
let\'s say I have the following code in A.cpp file: template <typename T> class A{ typedef T myType;

let's say I have the following code in A.cpp file:

template <typename T>
class A{
   typedef T myType;
   myType foo();
}

If I want to implement the foo function in this file , what is the syntax to write the function declaration? I though开发者_如何学Ct it'll be:

template <class T>
myType A<T>::foo(){
.
.
.
}

obviously it's wrong.


Yes, the typedef is only available within the class, and the return type is not in the class:

template <class T>
typename A<T>::myType A<T>::foo() {}


template <typename T>
typename A<T> :: myType A<T> :: foo ()
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消