0
我想初始化類Dlist的新對象。在聲明新對象後,指針第一個和末尾應該是NULL。當我聲明Dlist 臨時然而 - 構造函數沒有被識別,並且編譯器給它們賦值如0x0。我不知道爲什麼構造函數被識別。使用構造函數初始化雙鏈表中的NULL指針
// dlist.h
class Dlist {
private:
// DATA MEMBERS
struct Node
{
char data;
Node *back;
Node *next;
};
Node *first;
Node *last;
// PRIVATE FUNCTION
Node* get_node(Node* back_link, const char entry, Node* for_link);
public:
// CONSTRUCTOR
Dlist(){ first = NULL; last = NULL; } // initialization of first and last
// DESTRUCTOR
~Dlist();
// MODIFIER FUNCTIONS
void append(char entry);
bool empty();
void remove_last();
//CONSTANT FUNCTIONS
friend ostream& operator << (ostream& out_s, Dlist dl);
};
#endif
// implementation file
int main()
{
Dlist temp;
char ch;
cout << "Enter a line of characters; # => delete the last character." << endl
<< "-> ";
cin.get(ch);
temp.append(ch);
cout << temp;
return 0;
}
你知道NULL和0x0是相同的值嗎? – 2014-10-06 03:12:49
'0x0'意味着零,這通常是用來表示空的地址。 – 2014-10-06 03:13:15
你是什麼意思構造函數不被識別?你不能在調試器中進入它? – 2014-10-06 03:17:58