I´ve created a template class an initialized it. Now I wanna call a method from this class but I get a compiler error.
(With the Function TemporaryFunctionForSimulator
I successfully split the template class in *.h and *.cpp.
So that is NOT THE PROBLEM!)
Error: request for member ‘addEvent’ in ‘simulator’, which is of non-class type ‘Simulator*()’
Simulator.h
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include<queue>
#include<Event.h>
template<class T>
class Simulator
{
public:
void addEvent(T t);
Simulator();
virtual ~Simulator();
protected:
private:
};
#endif // SIMULATOR_H
Simulator.cpp
#include "Simulator.h"
#include <functional>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
template<class T>
Simulator<T>::Simulator()
{
}
template<class T>
Simulator<T>::~Simulator()
{
//dtor
}
template<class T>
void Simulator<T>::addEvent(T t)
{
//do something
}
// No need to call this TemporaryFunction() function,
// it's just to avoid link error.
void TemporaryFunctionForSimulator()
{
Simulator<int> TempObj();
}
main.cpp
Simulator<int> *simulator();
int t = 5;
simulator->addEvent(t); //error: request for member ‘addEvent’ in ‘simulator’, which is of non-class type ‘Simulator<int>*()’