Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 14.03.2015, 04:00   #1
goshek
Пользователь
 
Регистрация: 07.01.2014
Сообщений: 33
По умолчанию C++ has-a(containment) relationship

Есть класс Односвязный список

Код:
#include "ListInterface.h"
#include "Node.h"
//#include "PrecondViolatedExcep.h"
template < class ItemType>
class LinkedList : public ListInterface <ItemType>
{
private:
	Node < ItemType >* headPtr; // Pointer to first node in the chain
	// (contains the first entry in the list)
	Node <ItemType> * CurPtr;
	int itemCount; // Current count of list items
	// Locates a specified node in a linked list.
	// @pre position is the number of the desired node;
	// position >= 1 and position <= itemCount.
	// @post The node is found and a pointer to it is returned.
	// @param position The number of the node to locate.
	// @return A pointer to the node at the given position.
	Node<ItemType>* getNodeAt(int position) const;
public:
	LinkedList();
	LinkedList(const LinkedList<ItemType>& aList);
	virtual ~LinkedList();


	bool isEmpty() const;
	int getLength() const;
	bool insert(int newPosition, const ItemType& newEntry);
	bool remove(int position);
	void clear();
	ItemType peek(int position) const;
	/** @throw PrecondViolatedExcep if position < 1 or
	position > getLength(). */
	ItemType getEntry(int position) const; //throw(PrecondViolatedExcep);
	/** @throw PrecondViolatedExcep if position < 1 or
	position > getLength(). */
	void setEntry(int position, const ItemType& newEntry);
		//throw (PrecondViolatedExcep);
}; // end LinkedList
описание методов класса, опишу только один, для тестирования
Код:
#include"LinkedList.h"

template<class ItemType>
void LinkedList<ItemType>::clear()
{
	cout << "test";
	
}  // end clear
далее идет класс Циклический односвязный список

Код:
template < class ItemType>
class CircularListHasA : public CircularListInterface<ItemType>
{
private:
	ListInterface<ItemType> *listPtr;
	//Node < ItemType >* headPtr;
	//int itemCount;
public:
	//CircularListHasA();
	//CircularListHasA(const CircularListHasA<ItemType>& sList);
	//virtual ~CircularListHasA();

	bool insert(int place, const ItemType& value);

	bool remove(const ItemType& anEntry);
	//ItemType  retrieval(int position) const; 
	ItemType getEntry(const ItemType & anEntry);
	//virtual ItemType setEntry(const ItemType & anEntry);
	void clear();
	int getLength();
};
описание методов, опишу опять таки только один

Код:
#include "LinkedList.cpp"
#include "CircularListHasA.h"

template <class ItemType >
void CircularListHasA<ItemType>::clear()
{
	listPtr->clear();
}
ну и мейн

Код:
#include "CircularListHasA.cpp"
using namespace std;

int main()
{
	
	CircularListHasA <int> list;
	LinkedList <int> a;
	list.clear();
	getchar();
	return 0;
}
вопрос, почему при запуске возникает ошибка Необработанное исключение по адресу 0x008A651C в pr1.exe: 0xC0000005: нарушение прав доступа при чтении по адресу 0x00000000.
goshek вне форума Ответить с цитированием
Старый 14.03.2015, 08:19   #2
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,833
По умолчанию

Цитата:
описание методов класса, опишу только один, для тестирования
вы конструкторы показывайте, гле вы выделяете память под указатель, а то они вероятно у вас null...
p51x вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Could not establish trust relationship for the SSL/TLS flame33 ASP.NET 0 17.10.2013 14:46
Можно ли в DataSet установить relationship междщу таблицами? GenniY БД в Delphi 3 25.06.2010 12:23