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:
- When I use the
RedundantTypedeffor the return type ofgetTypedefedDataStructure(), I get a compiler error: ‘RedundantTypedef’ does not name a type - When I move
typedef std::map<std::string, StructName> RedundantTypedef;outside theHeaderTwoClassso I don't have to use the sametypedefinheader_one.hI 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