Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显式模板实例化:MSVC与GCC 我试图处理C++中的命名空间和模板。我可以在MSVC中编译以下代码(没有警告或错误),但是我对CYGWIN/GCC的各种排列没有任何运气。任何帮助都将不胜感激_C++_Templates_Instantiation_Explicit - Fatal编程技术网

显式模板实例化:MSVC与GCC 我试图处理C++中的命名空间和模板。我可以在MSVC中编译以下代码(没有警告或错误),但是我对CYGWIN/GCC的各种排列没有任何运气。任何帮助都将不胜感激

显式模板实例化:MSVC与GCC 我试图处理C++中的命名空间和模板。我可以在MSVC中编译以下代码(没有警告或错误),但是我对CYGWIN/GCC的各种排列没有任何运气。任何帮助都将不胜感激,c++,templates,instantiation,explicit,C++,Templates,Instantiation,Explicit,在头文件中,我声明了一个模板化的子类,如下所示: #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> *t

在头文件中,我声明了一个模板化的子类,如下所示:

#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;
}
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);
//...
}
当它显然是!:)无论如何,任何关于将此代码从MSVC移植到GCC的帮助都会有所帮助


谢谢

您的显式模板实例化看起来是错误的。尝试将其替换为

template class SmfsGrid_Typed<double, GDT_Float64>;
template class SmfsGrid_Typed<float, GDT_Float32>;
template class SmfsGrid_Typed<int, GDT_Int32>;
模板类SmfsGrid\u类型;
模板类SmfsGrid_类型;
模板类SmfsGrid_类型;

(注意添加的class关键字)

我远不是模板方面的专家,但我所知道的声明模板专门化的语法是
模板类SmfsGrid\u-Typed..@us2012,这是一种模板专业化(当您提供替代定义时);OP正在寻找模板实例化(使用现有定义)。
template class SmfsGrid_Typed<double, GDT_Float64>;
template class SmfsGrid_Typed<float, GDT_Float32>;
template class SmfsGrid_Typed<int, GDT_Int32>;