1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Function needs to be static in release build but virtual in debug?

Discussion in 'C++' started by lygray, Jun 23, 2010.

  1. lygray

    lygray New Member

    Jun 23, 2010
    Likes Received:
    Trophy Points:
    I have a quick question: I am working on a project where i need to do unit tests. I am trying to figure out a way to redefine the functions to virtual when unit testst are #defined, however, i am stuck with static.

    other than #defining a way to replace this word for all the source code, is there a way to get around this? In other words, a function foo needs to be static when used in the release but it needs to be virtual when used during unit testing. How can i acheive this?

    my first idea was using

    #ifdef unittest
    #define something_static virtual
    #define something_static static

    but I am not very familiar with this language yet and want someone to maybe juggle my mind a little for other options...


Share This Page