小编ABE*_*rov的帖子

第854页的"The C++ Programming Language Third Edition"中的代码是否正确?

我尝试学习C++.在"The C++ Programming Language Third Edition"一书中,我找到了第854页的代码(附录C.13.1):

template<class T> class X {
    static T def_val;
    static T* new_X(T a = def_val);
};

template<class T> T X<T>::def_val(0, 0);
template<class T> T* X<T>::new_X(T a) { /* ... */ }

template<> int X<int>::def_val<int> = 0;
template<> int* X<int>::new_X<int>(int i) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

我修改它:

template<class T> class X {
    static T def_val;
    static T* new_X(T a = def_val);
};

template<class T> T X<T>::def_val(0, 0);
template<class T> T* X<T>::new_X(T a) { return new T(a); …
Run Code Online (Sandbox Code Playgroud)

c++

13
推荐指数
2
解决办法
796
查看次数

标签 统计

c++ ×1