Search code examples
c++tuplestr1

Type problem when including tuple


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
  ...
};

Solution

  • 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 been TileMap::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.