类在名称空间错误中不存在 [英] class does not exist in namespace error
问题描述
我有以下课程
以下代码在Nurse.h
中定义
Hi,
I have following classes
following code is defined in nurse.h
#pragma once
#include "shift.h"
namespace Manage{
private ref class nurse
{
List<shift^> ^_daysServedlst;//here comes the error that shift is not defined in Manage Though it is available in auto complete list
...
};
}
以下代码块在shift.h
中定义
the following code block is defined in shift.h
#pragma once
#include "nurse.h"
namespace Manage
{
using namespace System;
using namespace System ::Collections ::Generic ;
private ref class shift : IComparable
{
};
问题是当我尝试在护士类的任何函数中创建shift类的对象时发生编译错误
错误消息错误C2039:"shift":不是"Manage"的成员
请帮助
the problem is the compilation error occurs when I try to make an object of shift class in any function of nurse class
Error message error C2039: ''shift'' : is not a member of ''Manage''
Please help
推荐答案
停止交叉包含头文件,您会很好的.例如,将声明放在一个头文件中.
您还需要转发类声明.例如:
Stop cross-include of your header files and you will be fine. Put the declarations in one header file, for example.
You also need forward class declaration. For example:
ref class BBB;
public ref class AAA {
BBB^ bbb;
//...
};
public ref class BBB {
AAA^ aaa;
//...
};
如果您不使用按值语义的实例的类引用,将是不可能的,这有明显的原因:由于无限的构造函数递归,实例化将导致无限的构造.
It won''t be possible if you used not class references by the instances in by-value semantic, by obvious reasons: instantiation would cause infinite construction due to infinite constructor recursion.
这篇关于类在名称空间错误中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!