Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Function in namespace - multiple definition

Function in namespace - multiple definition

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 Posts 3 Posters 0 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.
  • E Offline
    E Offline
    elelont2
    wrote on last edited by
    #1

    Hi, i cannot figure this out: hpp:

    namespace ContractStorage
    {
    std::string DoIt(ContractName c); // Declaration
    }

    cpp:

    namespace ContractStorage
    {
    std::string DoIt(ContractName c)
    {
    printf("yes");
    }
    }

    It says: multiple definition of `ContractStorage::DoIt(ContractStorage::ContractName)' How can this be, i only have the decalaration in the hpp file? I have a class declaration in the same file, it does not complain about that...

    L A 2 Replies Last reply
    0
    • E elelont2

      Hi, i cannot figure this out: hpp:

      namespace ContractStorage
      {
      std::string DoIt(ContractName c); // Declaration
      }

      cpp:

      namespace ContractStorage
      {
      std::string DoIt(ContractName c)
      {
      printf("yes");
      }
      }

      It says: multiple definition of `ContractStorage::DoIt(ContractStorage::ContractName)' How can this be, i only have the decalaration in the hpp file? I have a class declaration in the same file, it does not complain about that...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      There must be something else that is causing this that is external to your header file. I just tried that and it compiled without error. Does the error message give you any line numbers?

      E 1 Reply Last reply
      0
      • L Lost User

        There must be something else that is causing this that is external to your header file. I just tried that and it compiled without error. Does the error message give you any line numbers?

        E Offline
        E Offline
        elelont2
        wrote on last edited by
        #3

        I noticed that the issue only occurs when i use "_" as function name. When i set it to something else it will work. My namespace was named the same as my class, is it possible that the compiler did not detect the ambiguity?

        L 1 Reply Last reply
        0
        • E elelont2

          I noticed that the issue only occurs when i use "_" as function name. When i set it to something else it will work. My namespace was named the same as my class, is it possible that the compiler did not detect the ambiguity?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well for some reason (that cannot be seen from what you have provided), the function is being defined in more than one place. You need to go through all your code again to see where.

          1 Reply Last reply
          0
          • E elelont2

            Hi, i cannot figure this out: hpp:

            namespace ContractStorage
            {
            std::string DoIt(ContractName c); // Declaration
            }

            cpp:

            namespace ContractStorage
            {
            std::string DoIt(ContractName c)
            {
            printf("yes");
            }
            }

            It says: multiple definition of `ContractStorage::DoIt(ContractStorage::ContractName)' How can this be, i only have the decalaration in the hpp file? I have a class declaration in the same file, it does not complain about that...

            A Offline
            A Offline
            Albert Holguin
            wrote on last edited by
            #5

            Off the top of my head, one thing that may cause this message would be if you #include the header in multiple locations and have no header guards (either pragma once directive or #ifndef/#define/#endif method).

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups