编译头文件 [英] Compling the header file
本文介绍了编译头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个头文件
ClientServer.h
I''ve a header file
ClientServer.h
// ClientServer.h
#using <mscorlib.dll>
#using "BalanceInquiry.netmodule"
#pragma once
using namespace System;
// This code wraps the C# class using Managed C++
public __gc class BalanceInquiryC
{
public:
BalanceInquiry __gc *t;
BalanceInquiryC(){
t=new BalanceInquiry();
}
};
当我在上面的头文件中编译时,出现此错误:
When I compiled above header file, I got this error:
error C2143: syntax error : missing ';' before 'gc pointer'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C3160: 'int __gc *' : a data member of a managed class cannot have this type
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
如果有人知道,请帮助我.
If anyone knows, please help me.
推荐答案
成员BalanceInquiry
是该类的常规成员,而不是构造函数.那么,该成员的类型在哪里?
假设此片段之前的所有内容都是正确的,则可能是:
The memberBalanceInquiry
is regular member of the class, not a constructor. So, where is the type of this member?
Assuming everything before this fragment is correct, it could be:
public:
BalanceInquiry BalanceInquiry __gc *t;
但是,公共领域是不好的风格.相反,它应该是某个公共属性访问者使用const
...公开的私有字段,依此类推...
无论如何,都发现了您的直接bug.
But, then a public field is bad style; instead it should be a private field exposed by some public property accessor with const
... and so on...
Anyway, your immediate bug is spotted.
我的问题(上面的任何注释都没有帮助)是我的c#项目在类中有一个名称空间,该类可能会更改C ++中引用该类的方式
我的解决方案是从C#项目中删除名称空间声明,对其进行编译,然后在C ++项目中修复了编译错误
My problem, which was not helped by any of the above comments, was that my c# project i had the class inside a namespace, which presumably changes the way the class would be referenced in C++
My solution was to remove the namespace declaration from my C# project, compile it, and then the compile error was fixed in C++ project
这篇关于编译头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文