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. Linker Error #2005

Linker Error #2005

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiotutorial
4 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.
  • L Offline
    L Offline
    lubatomy
    wrote on last edited by
    #1

    I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)

    E D 2 Replies Last reply
    0
    • L lubatomy

      I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)

      E Offline
      E Offline
      emadns
      wrote on last edited by
      #2

      I doubt that in myclass.h, the function is declared as void myfunc(){ }; // with brackets. this is considered as a definition. Maybe.

      L 1 Reply Last reply
      0
      • E emadns

        I doubt that in myclass.h, the function is declared as void myfunc(){ }; // with brackets. this is considered as a definition. Maybe.

        L Offline
        L Offline
        lubatomy
        wrote on last edited by
        #3

        Im not exactly sure what you are trying to say with this are. I am not useing {} with the function in the class definition and that has been the stand that worked with every borland compiler I used in the past. I just recently started using Visual Studio.NET(2002) and now the convension gives me errors. I have even gotten errors trying to compile sample cade that was included with the Visual Studio Software. I wish I had the computer in front of me with compiler on it to try things out. but i have to wait till I get home to try anything.

        1 Reply Last reply
        0
        • L lubatomy

          I keep getting a linker Error 2005 about functions already being defined for every class I try and make in VS.net. I program my classes by putting the class definition in one file and them the actual code for the functions in a seperate file. for example: ***myclass.h file*** class myclass { public: void myfunc(); ..... ***myclass.cpp*** #include "myclass.h" void myclass::myfunc() { ....... This will always give me a linker error that there are two definitions for the function myfunc in the object file. I can make the error become a warning if I use the linker command /FORCE:MULTIPLE but that does not seem like the best way to overcome the problem even though the program will work fine when I do that. Does anyone have some helpfull suggestions to solving this problem. (I do not want to put the meat of the function in the class definition as sometimes the functions are rather big.)

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          lubatomy wrote: the class definition in one file and them the actual code for the functions in a seperate file These are the same thing. Typically, the declaration of a class typically goes in the .h file, and the definition of a class goes in the .cpp file. Anyway, at the top of the .h file, do you have something like:

          #if !defined(AFX_MYCLASS_H__83972473_D4D1_4923_9BD8_0FD75D2FB39C__INCLUDED_)
          #define AFX_MYCLASS_H__83972473_D4D1_4923_9BD8_0FD75D2FB39C__INCLUDED_

          #if _MSC_VER > 1000
          #pragma once
          #endif // _MSC_VER > 1000

          class myclass
          {
          }


          A rich person is not the one who has the most, but the one that needs the least.

          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