I have an application that I'm porting from C++ to Java. There is a section C++ code that I find really strange.
typedef std::string ArgName;
typedef std::map< ArgName, AnyData > ArgumentMap;
class Arguments : public ArgumentMap
{
public:
// Very important note: When read finds a numeric/set argument,
// it sets anyData.kind to Int. But STILL, it fills anyData.dString,
// just in case. So if the ArgumentMap was built by Arguments::read,
// the dString fields are all filled.
bool read( int argc, char **argv );
// remains is filled with the arguments not starting with '-'.
bool read( int argc, char **argv, std::vector<const char*>& remains );
// const if fails, erases arg if succeeds.
bool getNumericParam( const ArgName& name, int& num );
// sw is true if the switch is present. The function
// returns false if the argument value is not empty.
bool getSwitch( const ArgName& name, bool& sw );
bool getSwitchConst( const ArgName& name, bool& sw ) const;
// Returns true if the switch is present. Throws an error message if
// if the argument value is not empty.
bool getSwitchCompact( const ArgName& name );
void checkEmptyArgs() const;
};
It looks like in there original C++ the author is making their Arguments class inherit from a Map. This makes no sense to me. Map is an interface which means you can't inherit from it, you can only implement it. Is this something that can be done in C++ that you can't do in Java?
Also, I don't understand why you would use a typedef. I read the definition from Wikipedia
typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to form complex types from more-basic machine types[1] and assign simpler names to such combinations. They are most often used when a standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another
But I don't understand why the author would do that here. Are they trying to say that they want to inherit from the class AnyData and that ArgumentMap should have a Map as one of its fields?