samedi 24 janvier 2015

How to avoid typedef redundancy in two different header files?

I am trying to understand and then use the code written by someone else, but since I have little experience with typedef, I get confused at some point.


There are two different header files, one inheriting the other, and the same typedef is declared on both files.


Why does that redundancy occur, and how to avoid it?


header_one.h:



#include "header_two.h"
....

typedef std::map<std::string, StructName> RedundantTypedef;
....

class HeaderOneClass....


header_two.h:



....
struct StructName...
class HeaderTwoClass
{
public:
typedef std::map<std::string, StructName> RedundantTypedef;

std::map<std::string, StructName> getTypedefedDataStructure()
...


There are two basic issues which I don't understand here:



  1. When I use the RedundantTypedef for the return type of getTypedefedDataStructure(), I get a compiler error: ‘RedundantTypedef’ does not name a type

  2. When I move typedef std::map<std::string, StructName> RedundantTypedef; outside the HeaderTwoClass so I don't have to use the same typedef in header_one.h I again get an error. Error: ‘RedundantTypedef’ was not declared in this scope


What should be the correct arrangement of typedefs so I get no errors, and be able to use it as a return type for the getTypedefedDataStructure()


Aucun commentaire:

Enregistrer un commentaire