객체를 생성할 때 에러: request for member '..' in '..' which is of non-class type
조회수 8780회
클래스 안에 인자를 하나도 안 받는 생성자랑, int형 인자를 하나받는 생성자를 정의했습니다.
근데 main
함수에서 객체를 만들 때
파라미터 하나받는 생성자(2)는 괜찮은데 파라미터 하나도 안 받는 생성자(1)는 에러가 떠요! 왜죠?
에러내용
nonclass.cpp: In function ‘int main(int, const char**)’:
nonclass.cpp:17: error: request for member ‘bar’ in ‘foo2’, which is of non-class type ‘Foo ()()’
소스코드
class Foo
{
public:
Foo() {};
Foo(int a) {};
void bar() {};
};
int main()
{
//이건 괜찮음
Foo foo1(1);
foo1.bar();
// 이건 안 괜찮음
Foo foo2();
foo2.bar();
return 0;
}
댓글 입력