요리조리

C++ 컴파일 에러들 (C++ Compiler Errors) 본문

프로그래밍 언어/C++

C++ 컴파일 에러들 (C++ Compiler Errors)

나는수 2023. 2. 26. 23:02

컴파일러 에러: 

/usr/include/c++/11/ext/new_allocator.h(162): error: no instance of constructor "BvhNode::BvhNode" matches the argument list
            argument types are: (int, int, int, Aabb)
          detected during:
            instantiation of "void __gnu_cxx::new_allocator<_Tp>::construct(_Up *, _Args &&...) [with _Tp=BvhNode, _Up=BvhNode, _Args=<int, int, int, Aabb &>]" 
/usr/include/c++/11/bits/alloc_traits.h(516): here
            instantiation of "void std::allocator_traits<std::allocator<_Tp>>::construct(std::allocator_traits<std::allocator<_Tp>>::allocator_type &, _Up *, _Args &&...) [with _Tp=BvhNode, _Up=BvhNode, _Args=<int, int, int, Aabb &>]"

원인:

BvhNode 구조체(struct)의 생성자(constructor)를 작성하지 않아서 생긴 문제이다. (이 에러는 생성자를 잘못 작성(e.g. 생성자 함수의 매개변수를 틀리게 작성)하거나 잘못 호출(e.g. 매개변수 개수나 순서를 다르게 호출)하는 경우에도 발생하는 에러라고 한다.) 

구조체는 클래스랑 다르게 생성자를 따로 작성하지 않아도 된다고 착각했다. 아, 착각할 만하다! typedef struct 변수의 경우, 생성자가 필요 없다. 그냥 새로운 변수의 타입을 정의한다는 의미이기 때문이다. 그러나 그냥 struct의 경우는 좀 다르다. 해당 구조체의 인스턴스를 생성하기 위해서는 생성자의 정의가 필요하다. (정확히 둘의 차이가 뭔지 찾아보자!!)

 

참고 사이트:

https://cplusplus.com/forum/beginner/178748/

 

Need help with error on code - C++ Forum

Need help with error on code Create a class named Student. The class should consist of the following private data members : social security number and name (last, first or first, last?). The social security number (SSN) data member should be an integer. Th

cplusplus.com

 

Comments