托管类型的成员函数不能编译为非托管函数
A member-function of a managed type cannot be compiled as an unmanaged function
这是我程序中的第2种形式,它生成了上述错误。构造函数是生成错误的原因,我看不出为什么。它与我的主窗口的构造函数几乎相同,它工作得很好。
唯一的区别是这个需要论据。(即使我删除了 SettingsForm 构造函数中的参数,并恢复到void
,我仍然会收到相同的错误。
谁能告诉我为什么它似乎认为这个构造函数被编译为非托管功能?
设置表单.h
#pragma once
#pragma managed(push, off)
#include "SpriteyData.h"
#pragma managed(pop)
namespace Spritey {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace SpriteyData;
/// <summary>
/// Summary for SettingsForm
/// </summary>
public ref class SettingsForm : public System::Windows::Forms::Form
{
public:
SpriteySettings* currentSetLocCopy;//A local copy of our current settings.
SettingsForm(SpriteySettings* currentSettings)<------ERROR OCCURS HERE
{
InitializeComponent();
currentSetLocCopy = new SpriteySettings(*currentSettings); //take a copy of our current settings
//initialise the elements on our form to the values stored in the SpriteySettings
this->anchorDevCheckBox->Checked = currentSetLocCopy->isAnchorDevAllowed();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~SettingsForm()
{
if (components)
{
delete components;
}
if(currentSetLocCopy)
{
delete currentSetLocCopy;
}
}
private: System::Windows::Forms::Button^ CancelButton;
private: System::Windows::Forms::Button^ ApplyButton;
private: System::Windows::Forms::GroupBox^ editorSettingsGroup;
private: System::Windows::Forms::CheckBox^ anchorDevCheckBox;
private:
注意:以上只是构造函数 + 更多代码,只是导致错误的部分的代码示例。
这也是一个混合托管和非托管项目。
此
编译错误的重现:
#pragma managed(push, off)
class SpriteySettings {};
ref class Test
{
public:
Test(SpriteySettings* arg) {}
};
错误 C3280:"Test::Test":无法将托管类型的成员函数编译为非托管函数
以及一系列其他错误。 因此,诊断是此代码是在没有/clr 编译选项的情况下编译的。 由于这是一个 .h 文件,因此可能的原因是您在没有/clr 的情况下编译的.cpp文件中 #including 了它。 您需要找到该 #include 指令。
我也面临着同样的问题。在将 .Net 目标框架版本添加为 v4.5.1(以前缺少)时,该问题已解决
相关文章:
- 跨模板化函数编译的静态变量
- 无法使用 LoadObject() 函数编译 UE4 Actor。
- 为什么在使用转换构造函数编译代码时需要 const 复制构造函数?
- 函数编译,即使它不接受整数
- 使用C 模板函数编译时间递归
- 安卓 JNI - 'raw'函数编译失败
- C++就地析构函数编译警告
- 对 TR1 使用 boost 时提升数学特殊函数编译错误
- 显式复制构造函数编译错误
- 使用SSE内部函数编译一个简单的c++程序
- 函数编译时错误
- 模板函数编译错误
- C++:使用类型名作为基的模板类调用函数编译时错误
- 将 MATLAB 函数编译成可以在 linux 终端上运行的东西,w.out MATLAB
- boost::绑定不要使用成员模板函数编译
- C++函数编译错误
- 加速模板函数编译
- 如何在C++中使用辅助函数编译以下flex文件
- 如何让g++使用move构造函数编译c++11代码
- 同时将一组函数编译为.LIB和.DLL