아래 예제와 달리, 마지막 줄에 "abort has called called"오류가 발생합니다. 나는 이것이 왜 있어야하는지 안다.std :: vector abort problem
이 경우 명확하게하기 위해 abc-> def 대신 (* abc) .def를 사용하고 있습니다.
#include <iostream>
#include <string>
#include <vector>
class branch
{
public:
unsigned short n;
std::vector<branch> branches;
branch left()
{
return branches.at(0);
}
};
void main()
{
branch trunk = branch();
trunk.n = 0;
branch b1, b2;
b1.n = 0;
b2.n = 5;
b1.branches.push_back(b2);
trunk.branches.push_back(b1);
branch* focus1 = &(trunk.branches.at(0));
branch* focus3 = &(trunk.left());
std::cout<<trunk.left().branches.at(0).n<<std::endl; // ok
std::cout<<(*focus1).branches.at(0).n<<std::endl; // ok
std::cout<<(*focus1).left().n<<std::endl; // ok
std::cout<<(*focus3).branches.at(0).n<<std::endl; // problem
}
어떤 OS입니까? 무슨 컴파일러? 또한, (* p)보다 더 명확합니다 .def –
Windows Vista 및 VSC++ 2010 – alan2here