包含元组时的类型问题
我正在使用带有功能包 1 的 Visual Studio 2008。
我有一个像这样的 typedef typedef std::tr1::tuple
具有这样的函数 consttileInfo& GetTile(int x, int y) const
。
在实现文件中,该函数具有完全相同的签名(带有添加的类名限定符),并且我收到重新定义:不同类型修饰符
错误。 tileInfo&int&
而不是 tileInfo&
当我将鼠标悬停在标题中的函数类型(即 > 它会弹出一个小栏,上面写着static const inttileInfo
。我认为这可能是问题所在,但我不知道该怎么办。它让我相信编译器认为 std::tr1::tuple
如有任何帮助,我们将不胜感激,谢谢。
PS 这是一个模拟相同情况的示例,只是压缩到最小。
#include <tuple>
class Blah {
public:
typedef std::tr1::tuple<std::string, std::string, int> tileInfo;
tileInfo& GetTile( int x, int y ); // When you mouse over tileInfo in this line, it says static const int
...
};
I'm using Visual Studio 2008 with Feature Pack 1.
I have a typedef like this typedef std::tr1::tuple<std::string, std::string, int> tileInfo
with a function like this const tileInfo& GetTile( int x, int y ) const
.
In the implementation file the function has the exact same signature (with the added class name qualifier) and I am getting a redefinition: different type modifiers
error. It seems to be looking for an int&
instead of a tileInfo&
When I mouse over the type of the function in the header, i.e. tileInfo&
it brings up a little bar saying static const int tileInfo
. I think this may be the problem, but I'm not sure what to do. It leads me to believe that the compiler thinks std::tr1::tuple<std::string, std::string, int>
is a static const int
.
Any help is appreciated, thanks.
P.S. Here is an example emulating the same situation, just compacted to the minimum.
#include <tuple>
class Blah {
public:
typedef std::tr1::tuple<std::string, std::string, int> tileInfo;
tileInfo& GetTile( int x, int y ); // When you mouse over tileInfo in this line, it says static const int
...
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您在
typedef
中包含了头文件。听起来编译器无法看到
typedef
,因此tileInfo< 的类型/code> 默认为
int
。Make sure you included header file with the
typedef
.It sounds like compiler can't see the
typedef
so the type oftileInfo
defaults toint
.似乎当使用 typedef 作为返回类型或局部变量时,即使在类中,我也必须使用类名来限定它。例如,标头中的
GetTile
签名应该是TileMap::tileInfo& GetTile( int x, int y );
我认为当函数位于具有 typedef 的类中时,您不需要执行此操作。It seems that when using the typedef as a return type or a local variable, even within the class, I had to qualify it with the class name as well. For example the
GetTile
signature in the header should have beenTileMap::tileInfo& GetTile( int x, int y );
I thought that you didn't need to do this when the function is in the class with the typedef.