0

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

唯一的区别是这个需要一个参数。(即使我删除了 SettingsForm 构造函数中的参数,并恢复为void,我仍然得到同样的错误。

谁能告诉我为什么它似乎认为这个构造函数被编译为一个非托管函数?

SettingsForm.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:

注意:以上只是构造函数+一些代码,只是导致错误部分的代码示例。

这也是一个混合托管和非托管项目。

4

2 回答 2

4

重现此编译错误:

#pragma managed(push, off)
class SpriteySettings {};

ref class Test
{
public:
    Test(SpriteySettings* arg) {}
};

错误 C3280:“Test::Test”:托管类型的成员函数不能编译为非托管函数

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

于 2013-10-04T16:35:19.543 回答
0

我也面临同样的问题。在将 .Net Target Framework 版本添加为 v4.5.1(以前缺少)时,问题已解决

于 2019-05-28T05:04:46.203 回答