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 8827371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:21:20+00:00 2026-06-14T07:21:20+00:00

I am a beginner with OOP->I have a class Date with 3 private variable

  • 0

I am a beginner with OOP->I have a class Date with 3 private variable members and a should print the date in 2 ways:

  1. 12/25/2010
  2. December 25 2010

The following code it gives the error:

date.obj : error LNK2019: unresolved external symbol “public: __thiscall Date::Date(void)” (??0Date@@QAE@XZ) referenced in function “public: void __thiscall Date::printDate(void)” (?printDate@Date@@QAEXXZ)
What i am doing wrong?
date.h

#include<iostream>
#include<string>
#ifndef DATE_H
#define DATE_H
class Date
{
private:
    int day;
    int month;
    int year;
public:
    Date();
    Date(int d, int m, int y)
    {
        day=d;
        month=m;
        year=y;
    }
    int getDay() const {return day;}
    int getMonth() const {return month;}
    int getYear() const {return year;}
    void printDate(void);
};
#endif

date.cpp

#include"date.h"
#include<iostream>
#include<string>
const int NR=12;
void Date::printDate()
{
    Date newDate;
    std::string Months[]={"January","February", "March" , "April", "May", "June", "July", "August", "September", "Octomber", "November", "December"};
    int position;
    std::string month;
    position=newDate.getMonth();
    for(int i=0;i<NR;i++)
    {
        if(i==position)
        {
            month=Months[i];
        }
    }
    std::cout<<month<<" "<<newDate.getDay()<<" "<<newDate.getYear()<<std::endl;
}

main.cpp

#include "date.h"
#include <iostream>
int main()
{
    int d;
    int m;
    int y;
    std::cout<<"Enter day: ";
    std::cin>>d;
    std::cout<<"Enter month: ";
    std::cin>>m;
    std::cout<<"Enter years: ";
    std::cin>>y;
    Date newDate(d,m,y);
    std::cout<<newDate.getMonth()<<"/"<<newDate.getDay()<<"/"<<newDate.getYear()<<std::endl;
    newDate.printDate();
}
  • 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-14T07:21:21+00:00Added an answer on June 14, 2026 at 7:21 am

    The error is quite clear: you declared constructors for your Date class but didn’t define them inside the cpp file.

    You should add definitions for these constructors. They could just look like this:

    Date::Date() {}
    

    or maybe

    Date::Date() {
      d = 1;
      m = 1;
      y = 1970;
    }
    

    which at least wouldn’t print nonsense if you call

    Date myDate;
    myDate.printDate();
    

    EDIT:

    As suggested by Mat, you should use constructor initializer lists when you can. Your other constructor which uses parameters would look like this with an initialization list:

    Date(int d, int m, int y) : 
       day(d), month(m), year(y) {}
    

    In your case, your constructor calls the empty constructor on day, month and year and then assigns values to them, whereas when using initialization lists, the Date constructor calls constructors with parameters for day, month and year.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner in Android development. My code crashes. I have made a simple Java method
Beginner question: I have a dictionary where the values are lists of (a variable
Beginner programmer here. So bear with me. I have a simple python program. print
Beginner question. How come I can do this: Public Class Form1 Private StudentsInMyRoom As
Beginner iOS dev here. I have a problem in my array. Im making an
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Python beginner here, I have a list of lists and want to refer to
Question : Beginner Level Code: Pure Javascript I had created a web page in
I am very beginner to OOP and now I am trying to write some
I am currently a beginner in PHP OOP programming and was wondering if someone

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.