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

  • SEARCH
  • Home
  • 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 8391537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:17:22+00:00 2026-06-09T19:17:22+00:00

I am borring this example from the material i am going over. According to

  • 0

I am borring this example from the material i am going over. According to textbook, all is well here.

Yet, when trying to compile these files, i am getting a problem (see below)

3 files

Date.cpp:

    #include "Date.h"

    Date::Date()
    {
        setDate(1,1,1900);
    }

    Date::Date(int month, int day, int year)
    {
        setDate(month, day, year);
    }

Date.h:

class Date
{
public:
    Date ();
    Date (int month, int day, int year);

    void setDate(int month, int day, int year);
private:
    int m_month;
    int m_day;
    int m_year;
};

Main.cpp:

#include "Date.h"

int main () 
{
    Date d1 ;

    return 1;
}

When trying to compile with g++ *, i get

Undefined symbols for architecture x86_64:
  "Date::setDate(int, int, int)", referenced from:
      Date::Date()  in cc8C1q6q.o
      Date::Date()  in cc8C1q6q.o
      Date::Date(int, int, int) in cc8C1q6q.o
      Date::Date(int, int, int) in cc8C1q6q.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

When i declare Date *d; instead, program compiles.
When i declare Date *d = new Date instead, program fails.

What’s going on here please?

  • 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-09T19:17:23+00:00Added an answer on June 9, 2026 at 7:17 pm

    You haven’t provided a setDate method for your class. You declare it in the header file but you need to provide actual code for it as well.

    The error you’re seeing is the linker (ld) telling you that, although you have a piece of code trying to call that method, the linker has no idea where it is.

    You need to provide the method, such as putting the following into Date.cpp:

    void Date::setDate (int month, int day, int year) {
        m_month = month;
        m_day = day;
        m_year = year;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a solution for this problem. This is my example code:
For example, Notepad++ has a toolbar that looks like this: 7-Zip has a toolbar
I'm struggling since a few hours with this design question. In Cocoa for example,
My requirement is to match tags. In the example, this particular HourConstraint checks the
I see some websites use fancy icons. An example is this curly leaf icon
This seems like a very simple and a very common problem. The simplest example
This is kind of hard for me to express in English so an example
I'm trying to capture images from an IP camera in real time. The stream
I have a feeling I am completely borking this MySQL query but I'll ask
Boring of googling this question - how to set indentation offset for python in

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.