Den*_*lin 5 c++ compiler-errors metaprogramming
我有这个小模板类:
namespace emple {
template <class LinkedClass>
class LinkedInList
{
public:
LinkedInList()
{
active = false;
}
~LinkedInList(){}
LinkedClass* getNext() const
{
return next;
}
void setNext(LinkedClass* const next_)
{
next = next_;
}
void setActive(bool state)
{
active = state;
}
bool isActive()
{
return active;
}
private:
LinkedClass* next;
bool active;
};
};
Run Code Online (Sandbox Code Playgroud)
编译时我收到此错误:
类模板已经定义.
我究竟做错了什么?
bit*_*ask 16
这是由包含相同头文件(包含此模板类)的乘法引起的.这通常通过使用警卫在C++中解决:
#ifndef EMPLE_H
#define EMPLE_H
// your template class
#endif
Run Code Online (Sandbox Code Playgroud)
或#pragma onces(我知道的每个编译器都支持)并且不那么混乱:
#pragma once
// your template class
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10917 次 |
| 最近记录: |