Jump to content

C++ Calling something in a function

What's up guys, I'm trying to call this snippet of code,

OrderNode * OrderLL::createNode(Order* anOrder){
	//Giving this to you, b/c I am nice,
	//call createNode in the AddOrder, to create a node for the linked list
    OrderNode * onode=new OrderNode();
    onode->order=anOrder;
    onode->next=NULL;
    return onode;
}

into this function

bool OrderLL::AddOrder(Order* anOrder){
	//TODO: Implement ME

	if (head == NULL)
	{
		head = new OrderNode();
		tail = new OrderNode();
	}
	else
	{
		tail->next = new OrderNode();;
		tail = new OrderNode();
	}
}

 

I was wondering if new OrderNode = createNode(anorder) would be correct?

Thanks for the help in advance.

Link to comment
https://linustechtips.com/topic/679939-c-calling-something-in-a-function/
Share on other sites

Link to post
Share on other sites

8 minutes ago, PlutoNZL said:

This:


new OrderNode = createNode(anorder)

Isn't valid C++. What you want is:


OrderNode *orderNode = createNode(anOrder);

 

 
 
 
 

I tried that, but I receive the error that "expected a type specifier" 

bool OrderLL::AddOrder(Order* anOrder){
	//TODO: Implement ME
	OrderNode * OrderNode = createNode(anOrder);
	if (head == NULL)
	{
		head = new OrderNode;
		tail = new OrderNode;
	}
	else
	{
		tail->next = new OrderNode;
		tail = new OrderNode;
	}
}

This is the base code, I was looking at for the add order 

void Llist::Append(Node * NewNode)
{
	if (Head == NULL)
	{
		Head = NewNode;
		Tail = NewNode;
	}
	else
	{
		Tail->link = NewNode;
		Tail = NewNode;
	}
}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×