I'm very very new to c++.I'm truing to built a program to make new appointment etc.

#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Appointment;

class MyDate
{
      private:
             string date;
             string hour;
             
      public:           
             
             MyDate();//constructor xoris parametrous//
             
             
             void set_date(string _date)
                  {
                     date=_date;
                     } 
                     
             void set_hour(string _hour)
                  {
                        hour=_hour;
                       }                            
                                  
                     
                     
            friend void print(Appointment &,MyDate &)    ;     
            friend class Scedule;
                     
                     };                          
class Appointment
{
      private: 
      string description;
      string date;
      string hour;         
      public:
             
             
         Appointment();//constructor xoris parametrous//        
                                              
                            
            void set_description(string _description)
            {
                 description=_description;
                 }                
                            
                   
                   friend class MyDate;
                   friend class Scedule;
                   
               friend void print(Appointment &, MyDate &);
                                     
            };

         void print(Appointment &a,MyDate &d)
               {
                    cout<<"description of appointment "<<a.description<<endl;
                    cout<<"date "<<d.date<<"  hour "<<d.hour<<endl;
                    } 
                                                          
                    
            
    class Scedule
{
  vector<Appointment> m_apps;

public:
  void addAppointment(Appointment const & app)
  {
     m_apps.push_back(app);
  }
                               
                     
                   
friend class Appointment;
friend class MyDate;
};     


int main(int argc, char *argv[])
{
    Appointment app;
    MyDate dt;
    
  string tmpDesc;
  string tmpDate;
  string tmpHour;
  
  cout<<"Give description of appointment ";
    cin>>tmpDesc;
    cout<<"Give date of appointment  ";
    cin>>tmpDate;
    cout<<"Give hour of appointment  ";
    cin>>tmpHour;
      
    app.set_description(tmpDesc);
    dt.set_date(tmpDate);
    dt.set_hour(tmpHour);
    print(app,dt);
    system("pause");
    return 0;
}

the error is [Linker error] undefined reference to `Appointment::Appointment()'
[Linker error] undefined reference to `MyDate::MyDate()'

i'm sure that i have more things to do to this code,but now i would like your help to solve this error!

How?? Simple -- write the implementation code

class MyClass
{
public:
   MyClass()
   {
        cout << "Hello\n";
   {

Or if you don't want to or can't do it inline as above then put the code in a *.cpp file

class MyClass
{
public:
   MyClass();
   // blabla
};

// MyClass.cpp
#include "MyClas.h"

MyClass::MyClass()
{
   cout << "Hello\n";
}

You can also have empty constructors

class MyClass
{
public:
   MyClass() {}; // <<< empty constructor
}

Edited 5 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.