How to use class and function both in .h file



  • i want to use class which have declared function and that function is declared outside.
    but error shows that multiple definition of function error in qt


  • Moderators

    Why do you want to do this?
    In short: If you think you need to do this you're most probably doing it wrong. Just put the definitions in a .cpp file where they belong.

    Placing a body of the function in a header and then including that header in more than one place violates the one definition rule. Basically it means that your code gets compiled into every object file it is included in and the linker doesn't know which one to use when it links them together to produce the output executable.

    There are couple of exceptions to this rule, notably function templates, because they are instantiated at the place they are used, not defined, and inlined functions, because they are replaced with their bodies at the place they are used.


Log in to reply
 

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