C++ 托管类型的成员函数不能编译为非托管函数
这是我程序中的第二个表单,它生成了上面的错误。构造函数是产生错误的原因,我不明白为什么。它与我的主窗口的构造函数几乎相同,它工作得很好 唯一的区别是这一个需要一个论点。(即使我删除SettingsForm构造函数中的参数,并返回到C++ 托管类型的成员函数不能编译为非托管函数,c++,c++-cli,C++,C++ Cli,这是我程序中的第二个表单,它生成了上面的错误。构造函数是产生错误的原因,我不明白为什么。它与我的主窗口的构造函数几乎相同,它工作得很好 唯一的区别是这一个需要一个论点。(即使我删除SettingsForm构造函数中的参数,并返回到void,我仍然会得到相同的错误 有人能告诉我为什么这个构造函数被编译成非托管的吗 功能 设置形式h #pragma once #pragma managed(push, off) #include "SpriteyData.h" #pragma managed(pop
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一次
#pragma管理(推、关)
#包括“SpriteyData.h”
#布拉格语管理(pop)
名称空间精神{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
使用名称空间SpriteyData;
///
///设置表单摘要
///
公共引用类设置窗体:公共系统::Windows::窗体::窗体
{
公众:
SpriteySettings*currentSetLocCopy;//当前设置的本地副本。
SettingsForm(SpriteySettings*currentSettings)anchorDevCheckBox->Checked=currentSetLocCopy->isAnchorDevAllowed();
}
受保护的:
///
///清理所有正在使用的资源。
///
~SettingsForm()
{
if(组件)
{
删除组件;
}
如果(currentSetLocCopy)
{
删除currentSetLocCopy;
}
}
私有:系统::Windows::窗体::按钮^CancelButton;
私有:系统::Windows::窗体::按钮^ApplyButton;
私有:系统::Windows::窗体::GroupBox^编辑器设置组;
private:System::Windows::Forms::CheckBox^anchorDevCheckBox;
私人:
注意:以上只是构造器+更多的代码,只是导致错误的部分的代码示例
此外,这是一个混合的托管和非托管项目。针对此编译错误重新编写:
#pragma managed(push, off)
class SpriteySettings {};
ref class Test
{
public:
Test(SpriteySettings* arg) {}
};
错误C3280:“Test::Test”:托管类型的成员函数不能编译为非托管函数
以及一系列其他错误。因此,诊断是编译此代码时没有有效的/clr compile选项。由于这是一个.h文件,可能的原因是您#将其包含在未使用/clr编译的.cpp文件中。您需要找到#include指令。针对此编译错误重新编译:
#pragma managed(push, off)
class SpriteySettings {};
ref class Test
{
public:
Test(SpriteySettings* arg) {}
};
错误C3280:“Test::Test”:托管类型的成员函数不能编译为非托管函数
以及大量其他错误。因此,诊断是,此代码在编译时没有有效的/clr compile选项。由于这是一个.h文件,可能的原因是您#将其包含在一个在编译时没有/clr的.cpp文件中。您需要找到#include指令。我也面临同样的问题。在将.Net目标框架版本添加为v4.5.1(以前缺失),问题得到解决我也面临同样的问题。在将.Net目标框架版本添加为v4.5.1(以前缺失)时,问题得到解决该文件正在另一种形式的.h文件中包含d。尽管该.h文件设置为使用\clr编译,但它是
\include
d,介于pragma管理(推送,关闭)
和pragma管理(弹出)之间
。我将其移到这些指令之外,问题就解决了。再次感谢Hans。该文件正在另一个表单的.h文件中进行\include
d。尽管该.h文件设置为使用\clr编译,但它是\include
d,介于\pragma管理(推、关)
和pragma管理(弹出)之间
。我将其移到这些指令之外,问题就解决了。再次感谢Hans。