它只返回一个地址,没有任何调试器错误,尽管我的 DEV C++ 和 Code::Blocks 编译器都显示发送不发送 Windows 错误,但它们只初始化类对象,我已经包含了代码,谁能告诉我为什么会发生
#include <iostream>
#include <conio.h>
using namespace std;
struct Node
{
int data;
Node *nextptr;
};
class CLLIST{
private:
Node*firstptr;
Node*lastptr;
public:
CLLIST(){
cout << "Constructor Called !";
firstptr=lastptr=NULL;
}
void insert_at_back(int val){
if(firstptr==NULL) //it means start of C.LIST
{
Node*temptr = new Node; //means firstptr = temptr
firstptr->data=val;
firstptr=temptr;
firstptr->nextptr=firstptr;
} else{
Node*temp1 = new Node;
Node*temp2 = new Node;
temp1 = firstptr;
while(temp1->nextptr!=firstptr) //traversing
{
temp2 = temp1->nextptr;
temp2->data = val; //inserted at back
temp2->nextptr=firstptr; //circle completed
}
}
}
void printit(){
// functiont o print all the circular link lists data
Node*temp3ptr= new Node;
temp3ptr = firstptr;
while(temp3ptr->nextptr!=firstptr)//traversing
{
cout << temp3ptr->data;
cout << endl;
}
}
};
int main()
{
CLLIST obj1;
obj1.insert_at_back(10);
obj1.insert_at_back(20);
obj1.insert_at_back(30);
obj1.printit();
cout << "Done !";
getch();
}