[SOLVED] Disambiguation of Same Name Classes



  • I have a static library, aop_data that depends on another static library: DataCollection. The DataCollection library defines a namespace: cto4_data and in this namespace is a class named "State" The aop_data library also defines a class named "State" which is not scoped within a namespace. The problem I am having is that my Qt project is failing because its trying to use the wrong "State" class even though I am not explicitly specifying the cto4_data namespace AND I am including only the aop_data header for the State class in the class that is causing the problem:

    ../../../core/aop_data/hazards/AdsbTrajectoryChangeList.cpp:633:55: error: no member named 'getAltitude' in 'cto4_data::State'
    double altitude_delta = tcp.getAltitude() - state.getAltitude().getFeet();

    ~~~~~ ^
    ../../../core/aop_data/hazards/AdsbTrajectoryChangeList.cpp:636:44: error: no member named 'getAltitude' in 'cto4_data::State'
    TCR_DEBUG(2, "altitude is " << state.getAltitude() <<

    [...]

    There really should be no confusion about which version of "State" I am trying to use.

    I am asking this question here because this same situation exists in my non-Qt project, but MSVC++ does not complain about it. It's only my Qt project that is having this problem.



  • Turns out I was being too lazy with my INCLUDEPATH definitions. I was including .pri files which essentially declared library dependencies, which also specified include paths for that library. In most cases, all I really wanted were the include paths, but by putting the library dependencies in as well, I had to avoid circular dependencies which meant that the include path for cto4_data::State was defined before the include path for aop_data, so lines like #include "State.hpp" were bringing in the wrong class definition.

    The solution is to separate the INCLUDEPATH definitions from the library definitions, so they may be included independently from build order.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.