.
.
.
.
.
.
.
Hi,
I am as they say a beginner
I need to create a pointer to a linked list as a member variable. I have to tried todo this a number of ways but i dont think i understand the terminology.

i have a LinkedList.cpp file and a LinketList.h and and the main program. I'll post the LinkedLIst.h file

#include <cstdlib>
#include <string>
#include<iostream>
#ifndef MARK_FOO
#define MARK_FOO
#include "node.h"



struct node{ 
			std::string data;
			node* next;

			};
		
class LinkedList
{
typedef std::string value_type;
typedef size_t size_type;

public:

//constructors
	LinkedList();
		
		LinkedList(const LinkedList& obj);
	~LinkedList();
//mutating member functions
	void  Insert_Node_tail( node* tail_ptr, value_type entry);
	void  list_head_remove(node* head_ptr);
//Extractor fuctions

		size_type Node_count(){return many_nodes;}
		node* list_search(node* head_ptr, const value_type target);

		
		
private:
size_type many_nodes;
node* head_ptr;
node* current;
node* tail_ptr;
//specific Member functions
	bool IsList_empty();
//	node* LinkedList::LocateNode(size_type Target);

};
#endif
 

// in my int main() file i have written this to create a pointer to a linked list as a member variable

LinkedList* ptr = NULL;
*ptr =  List;
LinkedList& List;
LinkedList List = new LinkedList();

But i think im just lost.

Thanks for any input :)

Close on the code tags:

#include <cstdlib>
#include <string>
#include<iostream>
#ifndef MARK_FOO
#define MARK_FOO
#include "node.h"



struct node{ 
			std::string data;
			node* next;

			};
		
class LinkedList
{
typedef std::string value_type;
typedef size_t size_type;

public:

//constructors
	LinkedList();
		
		LinkedList(const LinkedList& obj);
	~LinkedList();
//mutating member functions
	void  Insert_Node_tail( node* tail_ptr, value_type entry);
	void  list_head_remove(node* head_ptr);
//Extractor fuctions

		size_type Node_count(){return many_nodes;}
		node* list_search(node* head_ptr, const value_type target);

		
		
private:
size_type many_nodes;
node* head_ptr;
node* current;
node* tail_ptr;
//specific Member functions
	bool IsList_empty();
//	node* LinkedList::LocateNode(size_type Target);

};
#endif

// in my int main() file i have written this to create a pointer to a linked list as a member variable

LinkedList* ptr = NULL;
*ptr =  List;
LinkedList& List;
LinkedList List = new LinkedList();

I need to create a pointer to a linked list as a member variable. I have to tried todo this a number of ways but i dont think i understand the terminology.

Well, then I won't ask you to clarify the terminology. :) Not sure what you mean by "as a member variable". "Member" of what?

I imagine you want this?

LinkedList* List = new LinkedList ();
LinkedList* ptr = List;

Now you have one LinkedList object (created in the first line with "new LinkedList ()"). You've defined List as a pointer to the LinkedList object you created. Then you create a second pointer in line 2 and point it to the same LinkedList object. Both List and ptr are pointers pointing to the same LinkedList object.

If that's not what you're looking for, please elaborate.

This article has been dead for over six months. Start a new discussion instead.