2017-11-14 9 views
0

나는 컴파일에 오류를 줄이 생성자가 : -오류 : 시대 착오적 이전 스타일의 기본 클래스 이니셜 라이저 [-fpermissive]

여기
Time::Time(short y,short m,short d,short h,short mi,short s): 
     (*this).y(y); 
     (*this).m(m); 
     (*this).d(d); 
     (*this).h(h); 
     (*this).mi(mi); 
     (*this).s(s); {}; 

가 전체 오류입니다 : - A와

Time.cpp: In constructor ‘Time::Time(short int, short int, short int, short int, short int, short int)’: 
Time.cpp:22:2: error: anachronistic old-style base class initializer [-fpermissive] 
    (*this).y(y); 
^
Time.cpp:21:61: error: unnamed initializer for ‘Time’, which has no base classes 
Time::Time(short y,short m,short d,short h,short mi,short s): 
                  ^
Time.cpp:22:9: error: expected ‘{’ before ‘.’ token 
    (*this).y(y); 
     ^
Time.cpp: At global scope: 
Time.cpp:22:9: error: expected unqualified-id before ‘.’ token 
Time.cpp:23:4: error: expected unqualified-id before ‘this’ 
    (*this).m(m); 
    ^~~~ 
Time.cpp:23:4: error: expected ‘)’ before ‘this’ 
Time.cpp:24:4: error: expected unqualified-id before ‘this’ 
    (*this).d(d); 
    ^~~~ 
Time.cpp:24:4: error: expected ‘)’ before ‘this’ 
Time.cpp:25:4: error: expected unqualified-id before ‘this’ 
    (*this).h(h); 
    ^~~~ 
Time.cpp:25:4: error: expected ‘)’ before ‘this’ 
Time.cpp:26:4: error: expected unqualified-id before ‘this’ 
    (*this).mi(mi); 
    ^~~~ 
Time.cpp:26:4: error: expected ‘)’ before ‘this’ 
Time.cpp:27:4: error: expected unqualified-id before ‘this’ 
    (*this).s(s); {}; 
    ^~~~ 
Time.cpp:27:4: error: expected ‘)’ before ‘this’ 
Time.cpp:27:17: error: expected unqualified-id before ‘{’ token 
    (*this).s(s); {}; 
       ^

을 noob 나는 무슨 일이 벌어지고 있는지 전혀 모른다. 인터넷 검색, 난 단지 도움이되지 않는 한 stackoverflow 링크를 찾을 수 있습니다.

+0

'(* this).'을 모두 삭제하십시오. –

+0

또한 모든 세미콜론을 일반 쉼표로 바꾸십시오 – UnholySheep

+1

비슷한 질문 https://stackoverflow.com/questions/29422285/error-anachronistic-old-style-base- 클래스 이니셜 라이저 – user2807083

답변

0

this을 사용하여 생성자 초기화 프로그램 목록에서 초기화하려는 클래스 구성원을 지정할 수 없습니다. this을 완전히 제거하십시오. 그것은 선호 또는 스타일의 문제가 아니라 단지 오류입니다.

"구식 기본 클래스"에 대한 오류 메시지는 구문상의 혼란에 불과합니다. 멤버 초기화 프로그램 목록의 무의미한 구문을 보면 컴파일러가 혼란스러워집니다.

+0

그리고 왜 이것을 downvoted입니까? 그것은 완전히 정확합니다. – Bathsheba

3

작성한 방법은 표준 C++가 아니므로 컴파일러 진단입니다. 종래의 구문을 다시 작성

Time::Time(short y,short m,short d,short h,short mi,short s): 
    y(y), 
    m(m), 
    // and so on, without a final comma 
{ 
} 

컴파일러는 함수 파라미터 이때 반원 변수 사이 구분할 수있다 : 처음 상태 y(y)y 부재를 매개로 y.

마지막으로 시간 유사 회원 인 경우 signed 유형을 원하십니까?

+0

'this->'문법으로 컴파일 할 수없고 에러 메시지가 덜 도움이됩니다 : [Compiler Explorer] (https://godbolt.org/g/d2gSa2) –

+2

'this->'in 생성자 초기화 목록은 단순히 불법입니다. "재래식"이 아닙니다. – AnT

+0

@ DanielH : 아마 시대 착오적 일 수도 있습니다! (실제로, 나는 단지 최신 GCC에서 그것을 시도했다. 그리고 그것이있다!) 나는 그것을 주석 처리했다. – Bathsheba

3

이니셜 라이저 목록을 사용하여 초기화 할 때는 이 아닌 ,으로 구분해야합니다. 그리고 this

Time::Time(short _y,short _m,short _d,short _h,short _mi,short _s): 
    y(_y), 
    m(_m), 
    d(_d), 
    h(_h), 
    mi(_mi), 
    s(_s) 
{ 
} 

내가 그것을이 경우, 중대한 오류 메시지가 아니라고 동의 도랑.

+0

마지막 편집은 필요하지 않습니다.'y (y) '의 범위 지정은 괜찮습니다. – rustyx

+0

컴파일러가 아니라 명확성을 위해 그것을 했나요? – Steve