Error that I can not figure out.

I am getting an error but I do not know why. But it should be a simple fix but I am just not seeing it.

Function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
template<typename generic>
void BST<generic>::insert(generic x)
{
	if(m_size == 0)
	{
		m_data = new BTN<generic>;
		m_data -> data = x;     // error here
		m_data -> p = NULL;
		m_data -> r = NULL; 
		m_data -> l = NULL;
		m_size++;
	}

}


.h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef BST_H
#define BST_H

#include"btn.h"
template<typename generic>
class BST
{
  public:
    BST();
    ~BST();
    void insert(generic x);
    void remove(generic x);
    bool search(generic x) const;
    void clear();
    bool empty() const;
    unsigned int size () const;

  private:
	unsigned int m_size;
	BTN<generic>* m_data;
};

#include"bst.hpp"
#endif 


error:
bst.hpp:20: error: invalid conversion from âintâ to âint

If you need to see more please let me know.
Just a guess here, but on line 11, try it this way?

void insert(const generic& x);

You would want to change it in line two of your function definition as well:

void BST<generic>::insert(const generic& x) {
Last edited on
I can't change the functions. When my teacher grades it won't work the way he test it if I change them.
Just guessing as well, but I think:

m_data -> data = x

should be

*(m_data->data) = x;
closed account (zb0S216C)
You need to point to the address of x like this:

 
m_data -> data = &x;
Last edited on
@Framework: That would be bad. You'd be storing the address of a temporary. That will only lead to pain and disappointment.
Topic archived. No new replies allowed.