Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:06:21+00:00 2026-06-17T14:06:21+00:00

I recently started working with c++ after a few years in other languages and

  • 0

I recently started working with c++ after a few years in other languages and I am having trouble getting code to compile with constructors. I know the problem is the constructor because if I comment it out everything works fine. I have copied some code directly from a c++ book and I am still getting errors. I am compiling in the command line with g++.
The compiler error:

Undefined symbols for architecture x86_64:
  "GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
      _main in ccoPO1iA.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Any help would be greatly appreciated

gradeBookTest.cpp

#include <iostream>
#include "GradeBook.h"

using namespace std;

int main()
{
GradeBook book1("newClass");
}

GradeBook.h

#include <string>

using namespace std;

class GradeBook
{
public:
GradeBook(string);
void setCourseName(string);
string getCourseName();
void displayMessage();

private:
string courseName;
};

GradeBook.cpp

#include <iostream>
#include "GradeBook.h"

using namespace std;

GradeBook::GradeBook(string name)
{
setCourseName(name);
}

void GradeBook::setCourseName( string name )
{
courseName = name;
}

string GradeBook::getCourseName()
{
return courseName;
}

void GradeBook::displayMessage()
{
cout << "this is the gradebook for\n" << getCourseName() << endl;
}

The indentation got messed up somehow when I copied the code into the browser…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:06:22+00:00Added an answer on June 17, 2026 at 2:06 pm

    You need to compile GradeBook.cpp as well along with gradeBookTest.cpp. This is happening because the compiler can see the constructor in the .h but come linking time, the function definition of that constructor is nowhere to be seen.

    g++ -o test GradeBookTest.cpp GradeBook.cpp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We recently started working with XML files, after many years of experience with the
I started working on CodeIgniter recently and I'm having some issues with the .htaccess
I just started having a problem where Apache will automatically restart after every few
I recently started working with Eclipse for Android development. When debugging through the code,
Recently I've started working on project VB for my As computing class, and after
Recently I started working with MVC, before that I used classic ASP.NET. After using
I have recently started working on a very large C++ project that, after completing
I recently started working with a client that had an index.html file with this
I recently started working with MVC or MVC2 to be more exact. I found
I've recently started working with an application written using Adobe Flex 3. We're using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.