2013-12-17 3 views
1

일년, 월, 일의 세 가지 변수가 포함 된 자체 클래스를 만들려고했습니다. 비교할 연산자를 두 개 추가합니다.나만의 날짜 클래스를 만들 수 없습니다.

헤더 :

#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 파일입니다 ': 반환 유형이 허용되지 않는 생성자

도움 주셔서 감사합니다!

+3

클래스 선언 끝에 세미콜론이 없습니다. – David

+1

헤더에 포함 파일이 필요한 이유가 무엇입니까? 당신은 머리말에서 그 (것)들을 사용하고 있지 않다! –

+0

cpp 파일이 추가 인클루드 파일을 사용하지 않습니다. * stdafx.h *를 제거하는 것이 좋습니다. 왜냐하면 작은 파일에 더 많은 문제가 발생하기 때문입니다. –

답변

2

클래스 정의 끝에 세미콜론이 없습니다.


기타 의견 :

  • (예를 들어 std::distance로) 이름 충돌을 방지하기 위해, 헤더에 전역 네임 스페이스에 using namespace std;을 넣지 마십시오.

  • <stdafx.h>은 Visual Studio 프로젝트에서 정의 된 비표준 헤더이므로 해당 코드는 Visual Studio에 종속됩니다. 프로젝트 설정에서 "미리 컴파일 된 헤더"를 끄면이 문제를 피할 수 있습니다.

0

클래스 또는 구조체의 선언은 ';'로 끝나야합니다. '

관련 문제