M
mast2as
Hi guys
Here's the class I try to compile (see below). By itself when I have a
test.cc file for example that creates an object which is an instance of
the class SpectralProfile, it compiles fine.
1 / Now If I move the getSpectrumAtDistance( const T &dist ) method
definition in SpectralProfofile.cc let's say the compiler says
core/profile.cc:199: error: `kNumBins' was not declared in this scope
core/profile.cc:199: error: template argument 2 is invalid
core/profile.cc:200: error: ISO C++ forbids declaration of
`getSpectrumAtDistance' with no type
core/profile.cc:200: error: prototype for `int
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)' does
not match any in class `wSubsurface::SpectralProfile<T>'
core/profile.hh:229: error: candidate is: wSubsurface::Vector<T,
wSubsurface::SpectralProfile<T>::kNumBins>
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)
core/profile.cc:200: error: template definition of non-template `int
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)'
That's my first problem... I know a bit about instanciation of
templated class in the cc file (to avoid linking errors). So would that
apply to those static const variables in that case too ?
2/
Basically kStart kEnd ... don't really have to be templated... only the
other member variables need to be.
So my question is... is there a way i can make the static variables
'untemplated' while the other are. This way when I call the function
getSpectrumAtDistance( const T &dist ) i don't have to do:
Vector<float, SpectralProfile<float>::kNumBins> vec =
spectralProfile->getSpectrumAtDistance( 0.1f );
which is a bit cumbersone... but maybe there's no better option ?
Thank you
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T>
class SpectralProfile : public TProfile<T>
{
public:
static const T kStart = 400.0;
static const T kEnd = 700.0;
static const T kBinEvery = 2.0;
static const int kNumBins = static_cast<int>( ( kEnd - kStart ) /
kBinEvery + 1 );
T *m_spectrums; //!< Continuous chunk of mem that holds data
public:
SpectralProfile( const char * spectralProfileFile );
~SpectralProfile();
Vector<T, kNumBins> getSpectrumAtDistance( const T &dist )
{
if ( dist <= this->m_minDistance ) {
return Vector<T, kNumBins>( T( 0.0 ) );
}
else if ( dist > this->m_maxDistance ) {
return Vector<T, kNumBins>( m_spectrums + ( this->m_numSamples -
1 ) * kNumBins );
}
}
};
Here's the class I try to compile (see below). By itself when I have a
test.cc file for example that creates an object which is an instance of
the class SpectralProfile, it compiles fine.
1 / Now If I move the getSpectrumAtDistance( const T &dist ) method
definition in SpectralProfofile.cc let's say the compiler says
core/profile.cc:199: error: `kNumBins' was not declared in this scope
core/profile.cc:199: error: template argument 2 is invalid
core/profile.cc:200: error: ISO C++ forbids declaration of
`getSpectrumAtDistance' with no type
core/profile.cc:200: error: prototype for `int
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)' does
not match any in class `wSubsurface::SpectralProfile<T>'
core/profile.hh:229: error: candidate is: wSubsurface::Vector<T,
wSubsurface::SpectralProfile<T>::kNumBins>
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)
core/profile.cc:200: error: template definition of non-template `int
wSubsurface::SpectralProfile<T>::getSpectrumAtDistance(const T&)'
That's my first problem... I know a bit about instanciation of
templated class in the cc file (to avoid linking errors). So would that
apply to those static const variables in that case too ?
2/
Basically kStart kEnd ... don't really have to be templated... only the
other member variables need to be.
So my question is... is there a way i can make the static variables
'untemplated' while the other are. This way when I call the function
getSpectrumAtDistance( const T &dist ) i don't have to do:
Vector<float, SpectralProfile<float>::kNumBins> vec =
spectralProfile->getSpectrumAtDistance( 0.1f );
which is a bit cumbersone... but maybe there's no better option ?
Thank you
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename T>
class SpectralProfile : public TProfile<T>
{
public:
static const T kStart = 400.0;
static const T kEnd = 700.0;
static const T kBinEvery = 2.0;
static const int kNumBins = static_cast<int>( ( kEnd - kStart ) /
kBinEvery + 1 );
T *m_spectrums; //!< Continuous chunk of mem that holds data
public:
SpectralProfile( const char * spectralProfileFile );
~SpectralProfile();
Vector<T, kNumBins> getSpectrumAtDistance( const T &dist )
{
if ( dist <= this->m_minDistance ) {
return Vector<T, kNumBins>( T( 0.0 ) );
}
else if ( dist > this->m_maxDistance ) {
return Vector<T, kNumBins>( m_spectrums + ( this->m_numSamples -
1 ) * kNumBins );
}
}
};