返回首页

我目前正在创建双在C继承与名单,其中有关于出版物的用户数据输入。该项目建立然而,当它进入出版物的第一个值(ISBN号)程序中断,给下面的错误:

未处理的异常在0x75045a0f在SDI2 Referal工作1.EXE:0XC0000005:存取违规读取位置0x00000014

它最初说,这个问题是在xstring但在搜索互联网后,我从项目属性发生改变。

这是我的联系list.h文件


#include <iostream> 

#include <string>

using namespace std;

 

class publication

 {

 public:

	 string isbn;

	 string publisher;

 };

 class book: public publication

 {

 public:

	 string author;

	 string title;

 };

 class procedings: public publication

 {

 public:

	 string editor;

	 string date;

	 string title;

 

 };

 

 class node

 {

	 friend class linkedList;

	 friend class book;

 public:

	 node();

	  node();

	 void setNextNode(node *next);

	 node* getNextNode(void);

	 void setPrevNode(node *next);

	 node* getPrevNode(void);

	 void setData(int *data);

	 int* getData(void);

 

 //private:

	 node *next;

	 node *prev;

	 int *data;

	 book *book;

	 procedings *procedings;

 };

 

class linkedlist

{

	friend class node;

public:

	linkedlist();

	void insertFromFront();

	void insertFromEnd();

	void deleteSpecifiedNode();

//private:

	node *first;

	node *last;

	node *current;

};

 

 node::node()

 {

	 next = NULL;

	 prev = NULL;

	 data = NULL;

	 book = NULL;

	 procedings = NULL;

 }

 

 linkedlist::linkedlist()

 {

	 first = NULL;

	 last = NULL;

	 current = NULL;

 }

 

void linkedlist::insertFromFront()

 {

 

 node *temp; 

 temp = new node; 

 

 //cout << "Enter 1 for book or 2 for procedings: ";

 //cin >> temp->data;



 //if (temp->data == 1)

 //{

	cout << "Enter the book ISBN number: ";

	cin >> temp->book->isbn;

	cout << "Enter the book Publisher: ";

	cin >> temp->book->publisher;

	cout << "Enter the book Author: ";

	cin >> temp->book->author;

	cout << "Enter the book Title: ";

	cin >> temp->book->title;

 /*}

 else if (temp->data == 2)

 {

	 cout << "Enter the Procedings ISBN number: ";

	 cin >> temp->procedings->isbn;

	 cout << "Enter the Procedings Publisher: ";

	 cin >> temp->procedings->publisher;

	 cout << "Enter the Procedings Editor: ";

	 cin >> temp->procedings->editor;

	 cout << "Enter the Procedings Conference date: ";

	 cin >> temp->procedings->date;

	 cout << "Enter the Procedings Title: ";

	 cin >> temp->procedings->title;

 }

 else

 {

	cout << "Enter 1 for book or 2 for procedings: ";

	cin >> temp->data;

 }*/

 

 temp->next = first;

 first = temp;

 }

 

//void linkedlist::insert_from_end()

// {

// node *temp, *temp1;

//  

// temp = new node;

//  

// cout << "Enter data: ";

// cin >> temp->data;

// temp->next = NULL;

//  

// if(head == NULL)

// head = temp;

// else{

// temp1 = head;

// while(temp1->next != NULL)

// temp1 = temp1->next;

// temp1->next = temp;

// }

// }

//void linkedlist::delete_specified_node()

// {

// node *N2D; //node to delete

// node *temp; // keep track of the node before deleting

// int node_num;

//  

// N2D = head;

//  

// cout << "Enter node num:";

// cin >> node_num;

//  

// temp->next = N2D->next;

// delete N2D;

// }

// 

//

//  

</string></iostream>

这是我的主cpp文件

{C}
我曾试图纠正这个问题的代码注释掉alot说。

任何帮助将不胜感激。提前感谢{S0的}:thorbarg

回答

评论会员:游客 时间:2012/02/04
?如果你只是想要一个名单,为什么不使用的std::列表总之,这里是一些建议:1。你应该分开的代码,输入代码插入到列表中的一个节点一个节点-否则,你需要复制多次,为每个函数的代码,插入一个节点,在前面,在年底或其他地方的中间列表。2。为此,应采取插入功能的节点作为参数3。插入时,你必须测试检查列表中是否仍是空或不是。生成的代码会有所不同。相反,从列表中删除一个节点后,你必须检查是否是最后一个元素。4。插入代码仅在前进方向的节点联系起来,而不是落后。5。我不明白为什么你需要的朋友声明,或为什么你需要使你的所有成员变量公开。也许你这样做只是为了避免可能的错误来源,但让我向你保证:你越是限制的知名度和访问权限,更好的,你将能够查明错误的来源
马克西米:在节点构造,你不建造(新)书或procedings。

在当前的设计,它应该是这样的:
node::node()

{

    next = NULL;

    prev = NULL;

    data = NULL;

    book = new book;

    procedings = new procedings;

}

在节点类,你应该只有一个成员的基类出版物;呼叫者responsability分配变量

{体C3}
和在代码中,你可以有这样的:

{的C4}

{C5的}马克斯:mbue
评论会员:游客 时间:2012/02/04
保持您的成员私人enshure,指针的所有权。公开成员函数指针:{5233}问候。