Windows Visual C++失败包括

Windows Visual C++失败包括,windows,namespaces,include,c++-cli,clr,Windows,Namespaces,Include,C++ Cli,Clr,我有两个相互依赖的头文件:BarP.h和addNewProductForm.h,它们是使用Microsoft CLR组件构建的,看起来像这样,它们太长了,无法包含完整的头文件: BarP.h: #pragma once #include "addNewProductForm.h" #include "editBarOptionsForm.h" #include "editDecayParamsForm.h" #include "editExistingItemForm.h" #include

我有两个相互依赖的头文件:BarP.h和addNewProductForm.h,它们是使用Microsoft CLR组件构建的,看起来像这样,它们太长了,无法包含完整的头文件: BarP.h:

#pragma once

#include "addNewProductForm.h"
#include "editBarOptionsForm.h"
#include "editDecayParamsForm.h"
#include "editExistingItemForm.h"
#include <math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <msclr\marshal.h>


namespace BarPricer3 {

    using namespace std;
    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 msclr::interop;

ref struct productDat{...};
productDat^ createProduct(String^ name,double firstPrice,double lastPrice,double lastDemand){...};
public ref class BarP{
    ...
    private: System::Void createNewProductForm(...){
        BarPricer3::addNewProductForm^ newProductForm = gcnew addNewProductForm;
        newProductForm->ShowDialog(this);
    }
}
addNewProductForm.h

#pragma once

#include "BarP.h"
#include <fstream>

namespace BarPricer3 {

using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

public ref class addNewProductForm{
        ...
    private: System::Void createNewProduct(...){
         productDat^ theNewP = createProduct(this->name->Text,Convert::ToDouble(this->firstPrice->Text),Convert::ToDouble(this->lastPrice->Text),Convert::ToDouble(this->lastDemand->Text));
        ...
    }
}
当我尝试编译时,会出现以下错误: 错误8错误C2039:'addNewProductForm':不是我的代码中'BarPricer3'd:…\BarP.h 690第32行的成员 错误15错误C2065:“productDat”:未声明的标识符d:…\addNewProductForm.h 181我的代码中的第19行


关于这里发生的事情,我能得到一些建议吗?

头文件中有一个循环包含,这与pragma once指令相结合,就是产生错误的原因。您需要删除其中一个包含项,或者同时删除这两个包含项,并用一个转发声明替换它们

您可能需要将实现分离到不同的文件中,因为您使用的是头中的类型


您的问题是addNewProductForm.h使用在BarP.h中定义的productDat,而BarP.h使用在addNewProductForm.h中定义的addNewProductForm。这些是需要向前声明的类。

谢谢。pragma once指令不是为了避免循环包含,还是我完全遗漏了什么?@deftfyodor不,pragma指令相当于包含警卫。同一个文件不会包含多次,但仅此而已。您仍然需要处理循环依赖关系。