I am getting a very confusing compiler error when building the following test code.
f:\data\sdks\smctc-1.00\examples\ik_pf\msvc\MarkerSampler.inl(16): error C2143: syntax error : missing ';' before 'MarkerSampler<MarkerT>::sample2'
f:\data\sdks\smctc-1.00\examples\ik_pf\msvc\MarkerSampler.inl(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Note sample builds without error, but sample2 is causing the problem. The only difference being one explicitly details the return type without the use of a typedef and the other uses the typdef’ed version.
.h file
#pragma once
#ifndef __MARKERSAMPLER_H_INCLUDED__
#define __MARKERSAMPLER_H_INCLUDED__
#include <vector>
#include <string>
#include <qthread.h>
#include <Wm5Vector3.h>
#include "UtilityFunctions.h"
#include "Marker.h"
#include "MarkerSet.h"
template <class MarkerT>
class MarkerSampler : public QThread
{
typedef std::vector<MarkerT> MarkerVector ;
typedef MarkerSet<MarkerT> MarkerSetT ;
typedef std::vector<MarkerSetT> MarkerSetVector ;
public :
MarkerSampler(const std::string inputDataDirectory, const unsigned int nSamples, const unsigned int startFrame, const unsigned int nFramesToUse) :
inputDataDirectory_(inputDataDirectory), nSamples_(nSamples), startFrame_(startFrame), nFramesToUse_(nFramesToUse) {seed = -time(NULL) ;}
~MarkerSampler() {}
std::vector<MarkerSet<MarkerT> > sample(const double scaleFactor = 1.0, const double noiseSD = 0.0) ;
MarkerSetVector sample2(const double scaleFactor = 1.0, const double noiseSD = 0.0) ;
protected:
void run();
private:
int seed ;
const std::string inputDataDirectory_ ;
const unsigned int nSamples_ ;
const unsigned int startFrame_ ;
const unsigned int nFramesToUse_ ;
} ;
#include "MarkerSampler.inl"
#endif
.inl file
template <class MarkerT>
std::vector<MarkerSet<MarkerT> > MarkerSampler<MarkerT>::sample(const double scaleFactor, const double noiseSD)
{
....
}
template <class MarkerT>
MarkerSetVector MarkerSampler<MarkerT>::sample2(const double scaleFactor, const double noiseSD)
{
....
}
The missing ; part of that error is slightly misleading, the compiler actually just doesn’t recognize the
MarkerSetVectortype. I think this is because it’s typedef’d inside theMarkerSamplerclass.If you explicitly state the scope of the typedef it should fix the error. Though (depending on your compiler at least) you may also need to add in the
typenamekeyword, sinceMarkerSetVectoris a dependant type. Here’s a fixed example: