您好我正在尝试为模板构建空函数,以便稍后填写详细信息。这是我的代码:
namespace my {
template <class T>
class Sptr {
private:
//some kind of pointer
//one to current obj
T obj;
size_t reference_count;
//one to original obj
public:
template <typename U> Sptr(U *);
Sptr(const Sptr &);
//template <typename U> Sptr(const Sptr<U> &);
~Sptr();
T* operator->() {return &obj;};
template <typename U> Sptr<T> &operator=(const Sptr<U> &);
//overload *,->,=,copy-constructor
// const-ness should be preserved.
// Test for null using safe-bool idiom
// Static casting, returns a smart pointer
};
template <typename U> Sptr<U>::Sptr(U* u) {
//do something
}
template <typename T> Sptr<T>::Sptr(const Sptr<T> ©Obj) {
//do copy constructor stuff
}
template <typename T> Sptr<T>::Sptr& operator=(const Sptr<T> &T) {
return *this;
}
}
但是当我编译它时出现以下错误。
Sptr.hpp:30:24: error: prototype for ‘my::Sptr<T>::Sptr(U*)’ does not match any in class ‘my::Sptr<T>’
Sptr.hpp:17:3: error: candidates are: my::Sptr<T>::Sptr(const my::Sptr<T>&)
Sptr.hpp:16:25: error: template<class T> template<class U> my::Sptr::Sptr(U*)
Sptr.hpp:38:24: error: ‘my::Sptr<T>::Sptr’ names the constructor, not the type
我该如何解决?