DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    version1 Guest

    Link Error : already defined ??


    I'm getting the following error when trying to Build the exe:

    "file:student.obj : error LNK2005: "public: void __thiscall Student::getData(void)"
    (?getData@Student@@QAEXXZ) already defined in main.obj"

    I've got a main.cpp, student.cpp, and student.h.

    The main.cpp basically calls the getData and showData functions in student.cpp.
    The student.h file defines a Student class, consisting of Name, Age, GPA.

    I've put the "#ifndef, #define, #endif" in the student.h. I'm not sure why
    I'm getting an error saying the getData (and showData) function is already
    defined.

    Any help will be greatly appreciated!!

    Thanks!


  2. #2
    Danny Kalev Guest

    Re: Link Error : already defined ??

    you have to show us how the getData member function is implemented in
    all three files. Could it be that you're #including Student.cpp in
    main.cpp? Alternatively, did you implement (rather than defined) this
    member function inside the header file? In short this error is the
    result of compiling the code of this member function (i.e., its body)
    more than once.

    Danny

    version1 wrote:
    >
    > I'm getting the following error when trying to Build the exe:
    >
    > "file:student.obj : error LNK2005: "public: void __thiscall Student::getData(void)"
    > (?getData@Student@@QAEXXZ) already defined in main.obj"
    >
    > I've got a main.cpp, student.cpp, and student.h.
    >
    > The main.cpp basically calls the getData and showData functions in student.cpp.
    > The student.h file defines a Student class, consisting of Name, Age, GPA.
    >
    > I've put the "#ifndef, #define, #endif" in the student.h. I'm not sure why
    > I'm getting an error saying the getData (and showData) function is already
    > defined.
    >
    > Any help will be greatly appreciated!!
    >
    > Thanks!


  3. #3
    version1 Guest

    Re: Link Error : already defined ??



    Danny,

    Thanks for the response! It took some experimenting, but I finally figured
    it out and you're right on...I was putting Student.cpp in the main.cpp.


    Thanks again.

    version1


    Danny Kalev <dannykk@inter.net.il> wrote:
    >you have to show us how the getData member function is implemented in
    >all three files. Could it be that you're #including Student.cpp in
    >main.cpp? Alternatively, did you implement (rather than defined) this
    >member function inside the header file? In short this error is the
    >result of compiling the code of this member function (i.e., its body)
    >more than once.
    >
    >Danny
    >
    >version1 wrote:
    >>
    >> I'm getting the following error when trying to Build the exe:
    >>
    >> "file:student.obj : error LNK2005: "public: void __thiscall Student::getData(void)"
    >> (?getData@Student@@QAEXXZ) already defined in main.obj"
    >>
    >> I've got a main.cpp, student.cpp, and student.h.
    >>
    >> The main.cpp basically calls the getData and showData functions in student.cpp.
    >> The student.h file defines a Student class, consisting of Name, Age,

    GPA.
    >>
    >> I've put the "#ifndef, #define, #endif" in the student.h. I'm not sure

    why
    >> I'm getting an error saying the getData (and showData) function is already
    >> defined.
    >>
    >> Any help will be greatly appreciated!!
    >>
    >> Thanks!



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links