【发布时间】:2017-05-05 14:31:00
【问题描述】:
error C2955: 'math::Array' : 使用类模板需要模板参数列表,有人知道我为什么会出错吗?
Array.h
#ifndef _ARRAY_
#define _ARRAY_
namespace math
{
template <typename T>
class Array
{
protected:
//! Flat storage of the elements of the array of type T
T * buffer;
unsigned int width, height;
public:
Array & operator = (const Array<T> & source);
};
} // namespace math
#include "Array.hpp"
#endif
Array.hpp
#ifndef _ARRAY_IMPLEMENTATION_
#define _ARRAY_IMPLEMENTATION_
namespace math
{
template<typename T>
Array & Array <T>::operator = (const Array<T>& source)
{
int size = 3 * getWidth() * getHeight();
Array<T> buffer = new Vec3<T>[size];
return *buffer;
}
} // namespace math
#endif
【问题讨论】:
-
请发minimal reproducible example。上下文很重要。
-
我怀疑返回值应该是
Array<T>& -
Array & Array <T>::operator =... firstArray应该是什么? -
@Someprogrammerdude 我无法更改声明,只能更改 Array.hpp 文件中的定义。
-
@Someprogrammerdude 数组是头文件中的一个类
标签: c++ list templates arguments operators