我得到一個Assertion failed
錯誤,指出Expression: invalid null pointer
,它指向c:\program files\microsoft visual studio 10.0\vc\include\xstring line:930
。空指針無效 - C++ - VS2010
這裏是我的代碼:
void main(void)
{
// fillMap() fills map with data from txtfile and returns map<char,int>
map<char, int> myMap = fillMap("file.txt"); // <- takes a string
MyClass *myObject;
// Code reaches here fine
myObject= new MyClass(myMap); // this line causes the error
// Does not get to here
}
在引起錯誤的行,我可以離開構造函數()空白,只說ptr = new MyClass();
,仍然得到同樣的錯誤。無論如何,我認爲它與我的構造函數有關。
在MyClass中,構造函數的定義是MyClass(char=' ', int=0)
。如果我不給他們的價值,那麼我得到一個No default constructor
錯誤。
那麼,有人能告訴我如何在Visual Studio 2010中跟蹤這個錯誤,或者提供一個可能的解決方案,以解釋爲什麼我會遇到這些問題?
PS,它不會讓我創建不是指針的新對象,Error: No operator "=" matches these operands
。
感謝您的任何幫助。
編輯:如果有幫助,這裏的線930 xstring:
_Myt& assign(const _Elem *_Ptr)
{ // assign [_Ptr, <null>)
_DEBUG_POINTER(_Ptr); //930
return (assign(_Ptr, _Traits::length(_Ptr)));
}
你可以發佈該構造函數的代碼嗎? – Mat 2011-04-06 22:22:20
'(char,int)'構造函數不是您要調用的構造函數。有沒有一個構造函數需要'map'? –
aschepler
2011-04-06 22:24:30