0

I have a class that I am essentially trying to override from an included utility project that my project depends on. I was hoping just creating the same class name in the main project would allow me to just simply overwrite the header that gets compiled, but instead i get

error C2011: 'Logger': 'class' type redefinition

Is there a way for me to essentially ignore the header that is compiled and overwrite it when I compile the newer version of the class?

joequest1
  • 37
  • 3
  • 7
    Short Answer: No. – NathanOliver Aug 11 '20 at 18:47
  • Once a `class`, or any entity is defined, then you can't change the definition without violating the [ODR](https://en.cppreference.com/w/cpp/language/definition). – cigien Aug 11 '20 at 18:48
  • you can use another, unique, name for self class, and replace name in self code – RbMm Aug 11 '20 at 18:48
  • @RbMm unfortunatly I can't access the class that calls the logger singleton, so my hope was to somehow overwrite it and create a new one with modified logic – joequest1 Aug 11 '20 at 18:50
  • I wonder if there is anything i can do with build events to somehow build my class first.. since the class is protected by ifdefs – joequest1 Aug 11 '20 at 18:51
  • what you try todo senseless – RbMm Aug 11 '20 at 18:52
  • Its a problem I have to try to work around. I don't want to do it lol – joequest1 Aug 11 '20 at 18:53
  • 1
    if usage of that original class is already in compiled library then no, you cannot. – Slava Aug 11 '20 at 18:53
  • Is this the only way to solve your problem? It would help if you posted some code with the interface for the logger and where it gets instantiated. Does the logger library have any configuration settings you can adjust to do what you want? Can you inject the logic you need to via template arguments or inheritance? Do you have access to the source code for the utility library to build a modified version? Are you allowed to switch to a different utility library? – mmackliet Aug 11 '20 at 19:23
  • I am afraid that there is no way to meet you needs. Maybe you could encapsulate your rewritten class into a lib. – Barrnet Chou Aug 12 '20 at 07:59

0 Answers0