Class Type Override Error

I get an error when creating a class object that says "Error C2011" dateType ": overriding the type" class "" I checked my class several times and it seems I don’t understand the cause of the error.

dateType.h

    #include <iostream>;
#include<string>;

using namespace std;

class dateType {
public:
    dateType();
    ~dateType();
    void setDate(string, int, int);

    void printDate()const;



private:
    string  day;
    int month;
    int year;

};

dateType.cpp

#include "dateType.h"
#include<iostream>;
#include <string>;
using namespace std;



dateType::dateType()
{
    cout << "please imput day,month,year";
    cin >> day >> month >> year;
}


dateType::~dateType()
{
}

void dateType::setDate(string d, int m, int y) {
    day = d;
    if (m <= 12)month = m;
    else { month = 0; year++; }
    year = y;


}
void dateType::printDate()const{
    cout << "day : \n" << day;
    cout << "month : \n" << month;
    cout << "year : \n" << year;

}

Thank.

+4
source share
1 answer

The problem was solved by adding #programa once so the code is as follows:

dateType.h

#pragma once
#include <iostream>
#include<string>



class dateType {
public:
    dateType();
    ~dateType();
    void setDate();

    void printDate()const;



private:
    std::string  day;
    int month;
    int year;

};

dateType.cpp

#include "dateType.h"
#include<iostream>
#include <string>
using namespace std;



dateType::dateType()
{

}


dateType::~dateType()
{
}

void dateType::setDate()
{
    string d;
    int m;
    int y;
    cout << "please imput day,month,year";
    cin >> d >> m >> y;
    day = d;
    if (m <= 12)month = m;
    else { month = 0; year++; }
    year = y;


}
void dateType::printDate()const{
    cout << "day : "<< day<<endl;
    cout << "month : " << month<<endl;
    cout << "year : " << year<<endl;

}

also deleted using namespace std;. Hope this helps if someone goes for the same error.

Thank.

0
source

Source: https://habr.com/ru/post/1694394/


All Articles