Hello

I'm new to computer programming , and I'm using Dev C++ 4.9.9.2. I'm also reading C++ How To Program Pearson International Edition from DEITEL as my source of knowledge. I don't if I'm reading the right book and using the right c++ software or compiler. Hop you can give me an advice regarding this.

I encountered a link error while compiling my programs or source file with file names GradeBook.h,GradeBook.cpp and fig3_10 I got this programs from the sample of my book C++ How To Program. But when I compiled it an error will occurred. I assume that the source file or the programs are coorrect because it come from the book of deitel.
GradeBook.cpp and fig3_10 has include Gradebook.h(#include "GradeBook.h").

Please help me these problems, because I can't go on with my self study without solving these problems, because most of the remaining illustration of the book is likely the same with this..

Thank you very much

Dani AI

Generated

Context: is using Dev-C++ 4.9.9.2 and the Deitel GradeBook sample files (GradeBook.h, GradeBook.cpp, fig3_10). rightly pointed to declaration/definition mismatches; asked for the actual linker output. The checklist and examples below cover the concrete causes that produce the typical "undefined reference" / linker errors and the exact fixes to apply when working with these three files.

  • Make sure both translation units are compiled and linked together. In Dev-C++ add both .cpp files to the same project (otherwise the IDE often compiles only the active file). From a shell use:

    g++ GradeBook.cpp fig3_10.cpp -o fig3_10
  • Compare every prototype in GradeBook.h with its definition in GradeBook.cpp. Match return types, parameter types, const and reference qualifiers, and namespaces. Default arguments belong only in the header, not in the .cpp.

  • Ensure each member implementation is scoped to the class. A correct pattern is:

    // GradeBook.h
    class GradeBook {
    public:
        GradeBook(const std::string& name);
        void setCourseName(const std::string& name);
    };
    
    // GradeBook.cpp
    #include "GradeBook.h"
    GradeBook::GradeBook(const std::string& name) { /* ... */ }
    void GradeBook::setCourseName(const std::string& name) { /* ... */ }
  • Check for simple typos and case mismatches: GradeBook vs Gradebook, #include "GradeBook.h" spelled exactly, and consistent use of std::string vs string (or using namespace std;).

  • Watch for vtable/virtual-related link errors: if the class declares a virtual destructor or virtual functions, those must have a definition (even if empty) in the .cpp.

  • If the linker error names a specific symbol (for example, undefined reference to 'GradeBook::GradeBook(std::string)'), that indicates the constructor or that signature is either missing or not linked — use that message to find which declaration lacks a matching definition.

Dev-C++ with MinGW will run Deitel samples, but the steps above resolve most linker problems seen in beginner projects: missing file in the build, signature mismatches, missing scope qualifiers, or omitted definitions.

Recommended Answers

All 2 Replies

Most generaly, link errors are caused by a mismatch in a function/method declaration and the actual implementation. Hence being unable to link the two (and possibly more in the case of overloading). For example, this would result in a link error:

void Foo(int, int);
int main()
{
    Foo(10, 10);
    return 0;
}
int Foo(void)
{
     return 0;
}

You need to post the link errors you are getting from the compiler so that we can help you.

commented: Yes, that would be good. +22
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.