I have a template linked list class, eg:

LinkedList<int> list1;
LinkedList<implicant> list_imp;

Now I need a Linked List of Linked Lists, This is how I declared

LinkedList<LinkedList<implicant> > list_of_lists;

Then I declared a Linked List of implicant class.

LinkedList<implicant> implicants_list;

I calculated some value and put them in the implicants_list.
Then I wanted to insert implicants_list into list_of_lists like this:

list_of_lists.InsertatLast(implicant_list);

BUT the program crashed because of the last statement. What's wrong with that? I have written the copy constructor for my LinkedList, and implicant is just a short structure with no more than three basic data types.
Please help ASAP, It's really urgent.

>BUT the program crashed because of the last statement.
How did it crash?

Run time error. I m sure it's related to pointers. Memory error to be specific.

I assume InsertatLast doesn't take a reference? Otherwise the copy constructor won't be called and you'll have nasty aliasing issues that could result in an access violation. If the crash is recurrent and predictable, I would recommend running your program in a debugger to find out exactly what instruction is causing the crash to occur, then you can trace back from there to find the source.

this is causing the crash:
list_of_lists.InsertatLast(implicant_list);

and no my InsertatLast() doesnt take reference. By the way I might have made a mistake writing the copy constructor, please check if there's any errors:

template<typename T>
LinkedList<T>::LinkedList(const LinkedList<T> &copy)
{
	for(Node<T> * c = copy.GetFirstNode(); c != NULL; c = c->GetNext())
		InsertatLast(c->GetItem());
		
}

>this is causing the crash:
>list_of_lists.InsertatLast(implicant_list);
I got that impression, but you're looking at at least two function calls from that, both of which could be causing your fault. Using a debugger, step through the program and into that function call. That way you can figure out a more precise location for the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.