使用名称空间的枚举时遇到问题 .
下面是函数调用:
object->writeMessage(tmpZone->getLineOne(), tmpZone->getLine(), tmpZone->getPosition());
来自编译器的问题来自
tmpZone->getLine()
来自Zone类(在insight命名空间中)的getLine()原型是:
Line getLine();
它在insight命名空间中返回枚举类型 . 此函数调用位于using namespace insight下的cpp文件中;线 .
编译器错误是
C:/WindRiver/workspace/SimpleTemplate/InsightLT.cpp:在静态成员函数中,静态int insight :: InsightLT :: taskFunction(insight :: InsightLT *)':C:/WindRiver/workspace/SimpleTemplate/InsightLT.cpp:161 :错误:没有用于调用insight的匹配函数:: InsightLT :: writeMessage(std :: string,Line,int)'C:/WindRiver/workspace/SimpleTemplate/InsightLT.cpp:82:note:候选人是:void insight: :InsightLT :: writeMessage(std :: string,insight :: Line,int)
我想不出为什么会这样 . Zone类也在insight命名空间中定义 . 有什么想法吗?
2 Answers
我能够编译这个,但我不知道为什么我的工作 . 为了完整性和封闭性,我想把它放在这里 .
我在命名空间范围内声明了行枚举和另一个枚举以及另一个类 . 我删除了枚举并将它们放在与以前相同的命名空间中的自己的头文件中,现在它编译 .
我不确定我错过了什么,这解决了这个问题 . 如果有人有任何考虑因素,请评论这可能已修复的内容 .
感谢那些试图提供帮助的人,抱歉我无法将一个示例放在一起显示错误 .
编译器无法从
insight namespace
解析Line
,您可以在函数定义中提供完整的命名空间,也可以在namespace insight
中包装cpp .尝试: