그래서 쉽게 생각할 수 있습니다.uniform 초기화를 사용하여 객체 및 포인터 객체를 초기화하면 작동하지 않습니다.
참고 : 아래 내용은 C++ 11 이상을 대상으로 한 것입니다.
시작해 보겠습니다. "Employee"라는 클래스가 있습니다.
Employee::Employee(const string& first, const string& last, const string& ssn)
: firstName(first), lastName(last), socialSecurityNumber(ssn) {}
또한
내 주에서 개체를 만들려고 할 때, 나는 다음을 수행하십시오 :
void main()
{
string firstName;
string lastName;
string socialSec;
Employee salariedEmployee{firstName, lastName, socialSec};
}
내가 오류 얻을 :
을 다음과 같이 그 consctructor입니다error: cannot declare variable 'salariedEmployee' to be of abstract type 'Employee'
그런 다음 객체를 pointe로 만들려고했습니다.
Employee *salariedEmployee{&firstName, &lastName, &socialSec};
을 오류를 얻을 : R로는 followes 내가 뭘 잘못 이해하지
error: scalar object 'salariedEmployee' requires one element in initializer
. C++ 11의 이전 버전은 코딩에 익숙했지만 중괄호 (uniform initialization)를 사용하는 새로운 방법을 배우려고합니다. 내가 뭘 잘못하고 있니?
P. 나는 많은 것을 봤지만 나는 무엇을해야하는지에 대해 매우 혼란 스럽다. 내가 저장 한의 resourses의 두이 있습니다 (하지만 훨씬 더 많은 물건을 읽고) :
- https://arne-mertz.de/2015/07/new-c-features-uniform-initialization-and-initializer_list/
- What are the differences between C-like, constructor, and uniform initialization?
'Employee'는 순수 가상 함수 (추상 유형)를 가지고 있습니다. 균일 한 초기화와 관련이 없습니다. –
@appleapple 또는 추상 기본 클래스에서 파생되었으며 전체 인터페이스를 구현하지 않았습니다. 어느 쪽이든, 오류는 Dimitris Pantelis가 예상하는 것 이외의 다른 곳에서 발생합니다. – Jodocus
@Jodocus yor 맞아 :) 그걸 잊어 버렸어. –