gpt4 book ai didi

c++ - 托管类型的成员函数不能编译为非托管函数

转载 作者:行者123 更新时间:2023-11-28 00:40:26 25 4
gpt4 key购买 nike

这是我程序中的第二种形式,它会产生上述错误。构造函数是产生错误的原因,我不明白为什么。它与我的主窗口的构造函数几乎相同,它工作得很好。

唯一的区别是这个有一个参数。 (即使我删除了 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) {}
};

error C3280: 'Test::Test' : a member-function of a managed type cannot be compiled as an unmanaged function

以及一系列额外的错误。因此诊断结果是此代码正在编译时没有有效的/clr 编译选项。由于这是一个 .h 文件,可能的原因是您将它#include 在一个没有/clr 的情况下编译的 .cpp 文件中。您需要找到 #include 指令。

关于c++ - 托管类型的成员函数不能编译为非托管函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19186238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com