在VS2013中使用NVCC编译时出现"modifier is not allowed on a destructor"错误

"modifier is not allowed on a destructor" error when compiled with nvcc in VS2013

本文关键字:not is modifier allowed on 错误 destructor VS2013 NVCC 编译      更新时间:2023-10-16

我在Visual Studio 2013上,正在尝试编译一个利用继承和C++11的CUDA代码。下面的代码返回"析构函数上不允许修饰符"错误,因为"覆盖"。

// derived.cuh
class derived : public base
{
 public:
  derived();
  ~derived() override;
};

其中基类的析构函数是虚拟的。完全相同的代码在 Ubuntu 上编译得很好。如果我将 .cu 和 .cuh 更改为 .cpp 并且启用了 .h,则完全相同的代码也可以使用默认的 Visual studio c++ 编译器进行编译。 C++11 已启用,因为如果"覆盖"附加到普通函数上,它也可以很好地编译。请参阅下面的示例,

// derived2.cuh
class derived2 : public base
{
 public:
  derived2();
  ~derived2();
  void func() override;
};  

其中 func() 是基类中的虚函数。

在VS2013中使用nvcc编译时,如何摆脱"析构函数上不允许修改器"错误?

向 NVIDIA 提交了这个错误,他们回复说这将在下一个 CUDA 版本(大概是 8.0)中修复。