//Using boost program options to read command line and config file data
#include
using namespace std;
using namespace b
Not necessarily the same problem as this guy had but here's something that caught me:
If you put your type in an anonymous namespace, there will be two classes with the same name but different instances and the casting will fail. For example:
a.hpp:
namespace {
class MyClass {...};
}
b.cpp:
#include "a.hpp"
cli_options.add_options()("test", po::value(), "test desc");
c.cpp:
#include "a.hpp" // THIS WILL MAKE A DIFFERENT "MyClass"
vm["test"].as(); // Fails at runtime.
It fails because the MyClass
in b.cpp
and the one in c.cpp
aren't the same class. Because of the anonymous namespace.
Removing the anonymous namespace solves the problem.