"expected unqualified id before '->' token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <typename T>
	void BSTClass<T>::InitializeNode(ND<T> node)
	{
		node = (ND<T>)malloc(sizeof(struct node));
		node->colour = "red";
		node->left = NULL;
		node->right = NULL;
	}

	template <typename T>
	void BSTClass<T>::InitializeTree(TD<T> tree)
	{
		tree = (TD<T>)malloc(sizeof(struct tree));
		tree->root = NULL;
		tree->size = 0;
	}


I promise this will be my last question here - but I'm getting this error on all the lines where I use the '->' symbol, 5 in all and they're the last 5 in the program (hopefully).

TD<T> tree and ND<T> node are pointers to the NODE<T> and TREE<T> structures of the tree and root, size, left, right, and colour are some of the elements in them (the elements I want to initialize - I have a data variable of type T in the node structure but I initialize it elsewhere).
> malloc(sizeof(struct node))
that makes no sense. There is no class called `node' (¿or is it?)
Maybe you intended to write malloc(sizeof(ND<T>))

However, given that `colour' is an std::string and you do have a member of type T, you should call the node constructor so its member are constructed properly
node = new ND<T>();

Then you may realize that you are modifying a local parameter, which would not have any effect except for leaking memory
That worked for InitializeNode(), but once I did the same for InitializeTree() I got a new error:

"no match for 'operator='(operand types are TD<T> and TD<T>*)"
actually scratch that it didn't work for InitializeNode() either
Should I post the whole program then? Sorry, most forums prefer if I post less code so that they'd have less to go over and I'm new to a lot of things here.
Not the whole program.
Just a bit more.
At least ND class.
That worked for InitializeNode(), but once I did the same for InitializeTree() I got a new error:

"no match for 'operator='(operand types are TD<T> and TD<T>*)"
That's because 'node' is a 'TD<T>' instance, and new returns a pointer-to-TD<T>.
Topic archived. No new replies allowed.