I am trying to deal with namespaces and patterns in C ++. I can get the following code to compile in MSVC (no warnings or errors), but I was not lucky with various permutations with CYGWIN / GCC. Any help would be appreciated.
In the header file, I declare a template subclass as follows:
#include <gdal.h>
namespace sfms {
template <class _type, GDALDataType _gdal> class SmfsGrid_Typed : public SfmsGrid_Base {
public:
SmfsGrid_Typed();
SmfsGrid_Typed(const SmfsGrid_Typed<_type, _gdal> *toCopy);
SmfsGrid_Typed(std::string filename);
virtual ~SmfsGrid_Typed();
virtual bool OpenRead();
virtual bool OpenWrite();
protected:
_type m_nodata_value;
virtual SfmsGrid_Base *New() const;
virtual SfmsGrid_Base *New(SfmsGrid_Base *toCopy) const;
virtual void initCopy(SfmsGrid_Base *copy) const;
};
template SmfsGrid_Typed<double, GDT_Float64>;
template SmfsGrid_Typed<float, GDT_Float32>;
template SmfsGrid_Typed<int, GDT_Int32>;
typedef SmfsGrid_Typed<double, GDT_Float64> SmfsGrid_Double;
typedef SmfsGrid_Typed<float, GDT_Float32> SmfsGrid_Float;
typedef SmfsGrid_Typed<int, GDT_Int32> SmfsGrid_Int;
}
In the source file, I create a custom template class as follows:
void hi_there() {
sfms::SmfsGrid_Typed<int, GDT_Int32> *grid = new sfms::SmfsGrid_Typed<int, GDT_Int32>(filey);
sfms::SmfsGrid_Int *grid2 = new sfms::SmfsGrid_Int(filey);
}
GDALDataType is an enumeration, but it does not seem to be a problem.
I tried declaring the class inside and outside the namespace, without success.
The source file containing the implementations for the templates is compiled with both compilers.
I tried to remove the explicit template creation and include the corresponding C ++ source file, also without joy.
'template', 'typename' 'typedef' ( def'n ) , GCC, :
error: 'SmfsGrid_Typed' is not a member of 'sfms'
!:) , MSVC GCC .
!