여러 클래스가있는 꽤 긴 프로그램이 있으므로 필요하지 않으면 게시하지 않을 것입니다. 그러나 메인 리턴 후에 세그먼트 결함이 발생합니다.메인 이후의 분할 오류 11 번
나는이 오류가 볼 수있는 GDB를 사용 :
program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000002300103be8
0x00000001000035cc in std::_Rb_tree<std::string, std::string, std::_Identity, std::less, std::allocator >::_S_right (__x=0x2300103bd0) at stl_tree.h:512
512 { return static_cast<_Link_type>(__x->_M_right); }
나는 C 아주 새로운 해요는 ++ 그래서 이것은 단지 나에게 횡설수설처럼 보인다. 누구든지 그것을 해독 할 수 있습니까? 내 STL 컨테이너 중 하나가 문제의 원인 일 수 있습니까? 그것을 고치는 방법에 대한 조언? 코드와
편집 : 블록 main
의 경우이 어딘가에 그것을 아래로 격리 한 있도록
좋아, 그것은 내가 쓴 마지막 일이었고, 내가 그것을 주석 때 프로그램이 잘 실행됩니다.
else if(line.substr(0, 3) == "Rec") // Recieve
{
istringstream ss(line);
string s; // output string
string upc;
string name;
int amount;
int count = 0;
while(ss >> s) // go through the words in the line
{
count++;
if(count == 2)
upc = s;
else if (count == 3)
{
istringstream isa(line.substr(20, 2));
isa >> amount; //Parse the amount
}
else if (count == 4)
name = s;
}
warehouses.find(name)->second.receive_food(upc, amount); //add the food to the warehouse
}
우리가보고있는 line
이 형식에 명확히하기 위해 : 여기
map<string, a4::warehouse> warehouses; //all the warehouses.
창고입니다받을 방법
void warehouse::receive_food(std::string upc, int amount)
{
items.find(upc)->second.receive(amount);
todays_transactions = todays_transactions + amount;
}
:
Receive: 0984523912 7 Tacoma
warehouses
하는지도입니다
어디 items
는 std::map<std::string, food> items;
되고 crates
이 std::list<crate> crates;
을 어디에 마지막으로 음식이 방법을
void food::receive(int amount)
{
crates.push_back(crate(life, amount));
}
수신 그리고 crate
는
class crate
{
public:
crate(int, int);
~crate();
int life;
int quantity;
};
코드가 필요합니다. –
첫 번째 추측 : 원시 포인터를 많이 사용하면 어딘가에서 잘못되어 이제는 일부 기능이 STL segfaults의 깊숙한 곳에서 작동합니다. 행운을 비네, 이러한 종류의 것들은 * 하드 * 디버깅 할 수 있습니다. 만약 가능하다면, 프로그램을 디버그 기호로 컴파일하고'valgrind'로 테스트하십시오. – us2012
코드를 게시하기 전에 줄이십시오. 오류를 나타내는 가능한 가장 작은 프로그램으로 축소하십시오. 그런 다음 질문에 * 해당 프로그램을 게시하십시오. http : // SSCCE를 참조하십시오.해당 디버깅 기술에 대한 자세한 내용은 ORG를 참조하십시오. –