我有两个相互依赖的头文件: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行)
我可以就这里发生的事情得到任何建议吗?
答案 0 :(得分:0)
您在头文件中包含循环,并且与#pragma once
指令结合使用会产生错误。您需要删除其中一个(或两者)并使用转发声明替换它们(可能想要谷歌这一点)。
您可能需要将实现分离到不同的文件,因为您使用标头内的类型。
您的问题是,addNewProductForm.h
使用productDat
中定义的BarP.h
,BarP.h
使用addNewProductForm
中定义的addNewProductForm.h
。 (这些是需要向前声明的类。)