lundi 27 février 2017

Unable to pass macro definition to base class

Base class is not able to view the macros defined in the derived class on the creation of derived class object. [C++14]

Base.HPP

 class Base {
          public:
            Base() {
               #ifndef SKIP
               std::cout << "Bing" << std::endl;
               #endif
             }
    };

File : Derived.HPP

#define SKIP
class Derived : public Base {
   public:
   Derived() {}
};

So, whenever I create the object of Derived class I expected not to see the "Bing" in the output terminal since I have defined the macro "SKIP".

But this does not happens. It seems Base class is clueless about the definition of macro "SKIP". Is there a way to do it or this is not possible to do it without compiling the code with -DSKIP flag?

Aucun commentaire:

Enregistrer un commentaire