0

In a C++ Program, attempting to use templates in a class I'm developing results in my compiler not registering the class constructors declared in the source.

If I remove the template it compile fine, but other that that in the last hour I've made no progress to in what might be wrong (I've tried playing with where and how I declare the template, and namespace syntax's) .

So, what am I failing to understand about C++, please?

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()
}
Vera F W C
  • 208
  • 3
  • 11
  • 3
    Template definitions work best in the header file. Move the constructor's definition to the header, either inline in the class or below the class definition. Applies to the other functions as well. – Niall Feb 18 '16 at 07:49
  • 1
    Move that code in cpp file to h file. – Danh Feb 18 '16 at 07:49

0 Answers0