在 C++ 程序中,尝试在我正在开发的类中使用模板会导致我的编译器没有注册在源代码中声明的类构造函数。
如果我删除模板,它编译得很好,但除此之外,在过去的一个小时里,我在可能出错的问题上没有取得任何进展(我尝试过在哪里以及如何声明模板以及命名空间语法)。
那么,请问我对 C++ 有什么不明白的地方吗?
rondel.h:
template <typename T>
class RondelGauge: public sf::Drawable, public sf::Transformable {
private:
//No Default constructor
RondelGauge();
//Used to draw the gauge
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
//The data the gauge visualises
T& dataValue;
std::string& label;
std::string& dataUnit;
[Irrelevant code emitted]
public:
//The constructor - No errors thrown in the header.
RondelGauge(T& value, std::string& iLabel, std::string& iUnit);
};
rondel.cpp:
#include "rondel.h"
#include "stdafx.h"
template <typename T>
//This, and variations of it, fail to reguister.
RondelGauge<T>::RondelGauge(T& value, std::string& iLabel, std::string& iUnit) : dataValue(&value), label(&iValue), dataUnit(&iUnit) {
setOrigin(65 / 2, 65, 2);
setPosition()
}