我正在设计一个命名空间内的模板类,我不明白为什么我得到这个错误:'测试'没有命名一个类型。它似乎只给我这个构造函数和析构函数定义的错误。任何帮助将非常感激。C++错误:不命名类型,模板类
注意:我这样做是为了一个班级作业,并且必须保持这些文件的设置方式。我必须在test.h中包含一个test.h文件和test.hpp。
test.h:
#ifndef TEST_H
#define TEST_H
namespace mynamespace
{
template <typename A, typename B>
class Test
{
public:
// constructor
Test();
// destructor
~Test();
};
}
#include "test.hpp"
#endif
test.hpp:
// constructor
template <typename A, typename B>
Test<A, B>::Test()
{
}
// destructor
template <typename A, typename B>
Test<A, B>::~Test()
{
}
main.cpp中:
#include "test.h"
using namespace mynamespace;
int main()
{
return 0;
}
生成文件:
CC = g++ -std=c++11 -Wall -pedantic
main.x: main.o
$(CC) -o main.x main.o
main.o: main.cpp test.h
$(CC) -c main.cpp
clean:
rm *.o *.x
这是排字错误?有两个As。 'template' –
MFisherKDX
'test.hpp'和'test.h'? – nikomaster
是的,这两个As是一个错字。 – gabsiew