클래스 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가 같은 값임을 이해하십니까? –
'0x0'은 0을 의미하며, (보통) null을 나타내는 데 사용되는 주소입니다. –
생성자가 인식되지 않는다는 것은 무엇을 의미합니까? 디버거에서이 단계로 들어갈 수 없습니까? –