일년, 월, 일의 세 가지 변수가 포함 된 자체 클래스를 만들려고했습니다. 비교할 연산자를 두 개 추가합니다.나만의 날짜 클래스를 만들 수 없습니다.
헤더 :
#ifndef DATE_H
#define DATE_H
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
using namespace std;
class Date {
public:
int day;
int month;
int year;
Date(int m, int d, int y);
bool operator< (const Date &) const;
bool operator== (const Date &) const;
}
#endif
CPP : 오류가
오류 C2533은
#include "stdafx.h" #include "date.h" Date::Date(int m, int d, int y) :day(d),month(m),year(y){} bool Date::operator< (const Date & d2) const { bool result; if(year<d2.year){ result=true; } else if (year==d2.year&&month<d2.month){ result=true; } else if (month==d2.month&&day<d2.day){ result = true; } else{ result = false; } return result; } bool Date::operator== (const Date & d2) const { return (year==d2.year)&&(month==d2.month)&&(day==d2.day); }
입니다
: '날짜 : {ctor에} 여기 내 헤더 파일과 CPP 파일입니다 ': 반환 유형이 허용되지 않는 생성자
도움 주셔서 감사합니다!
클래스 선언 끝에 세미콜론이 없습니다. – David
헤더에 포함 파일이 필요한 이유가 무엇입니까? 당신은 머리말에서 그 (것)들을 사용하고 있지 않다! –
cpp 파일이 추가 인클루드 파일을 사용하지 않습니다. * stdafx.h *를 제거하는 것이 좋습니다. 왜냐하면 작은 파일에 더 많은 문제가 발생하기 때문입니다. –