私は次の例で問題が発生しています。最後の行は "abort has called"というエラーを生成しています。なぜこのようにすべきかわかりません。std :: vector abortの問題
この場合、わかりやすくするために、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