Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to use class and function both in .h file
Forum Updated to NodeBB v4.3 + New Features

How to use class and function both in .h file

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 759 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • qt_ankit_developerQ Offline
    qt_ankit_developerQ Offline
    qt_ankit_developer
    wrote on last edited by A Former User
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved