Class has no member named function

Hi guys,
This error is really annoying me but its late and i've been programming all day so I might be missing something stupid.
I keep getting an error saying ui.h:30: error: 'class BTree<Word>' has no member named 'prntInOrder'

here is my ui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once

#include "btree.h"

#include <fstream>
#include <iostream>
using namespace std;

class UI
{
	public:
		void go (string filename);
		void help ();
	private:
		BTree<Word> tree;
		
		bool load(string filename);
};


ui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "ui.h"

void UI::help()
{
	cout << "::Binary Search Tree::" << endl;
	cout << endl;
	cout << "Usage: Tree <filename>" << endl;
}

void UI::go(string filename)
{
	if (!load(filename))
		return;
	tree.printInOrder();
	
}


and part of my btree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include "node.h"

#include <iostream>
using namespace std;

template<class T>
class BTree
{
	public:
		
		BTree (): root(NULL){};
		~BTree ()
		{
			clear(root);
		}
		void printInOrder()
		{
			count = 1;
			printInOrder(root);
		}
		
	private:
		
		Node<T>* root;
		
		void printInOrder(Node<T>* node)
		{
			printInOrder(node->getLeft());
			cout << node->getData() << endl;
			printInOrder(node->getRight());
		}
};


As you can see the printInOrder() function is there so would it not see it?
You are calling:
tree.printInOrder(); (no parameters)

Your function is:
void printInOrder(Node<T>* node) (1 parameter)


You need to give it a parameter.


EDIT: crap, just saw the other overload, nevermind...
Last edited on
You should show the whole error message and the place in your code where the function is called.
ui.h: In member function 'void UI::go(std::string)':
ui.h:30: error: 'class BTree<Word>' has no member named 'printInOrder'

ui.h:30 doesnt exist but the place that im calling printInOrder is line 14 in ui.cpp
What is tree in this code?

void UI::go(string filename)
{
if (!load(filename))
return;
tree.printInOrder();

}
BTree<Word> tree;
as shown in line 15 of ui.h
I do not see the definition of tree. So your presented code is not adequate to the proiblem.
> ui.h: In member function 'void UI::go(std::string)':
> ui.h:30: error: 'class BTree<Word>' has no member named 'printInOrder'
> ui.h:30 doesnt exist ...

Do uou have more than one file ui.h?

Are you using an IDE of some kind, and compiling the code from within the IDE?

If so, perhaps the files that you think are being compiled are not the files that are actually compiled.
Im compiling with g++ on the console using a makefile and I only have 1 ui.h

Makefile
1
2
3
4
5
6
7
8
9
10
11
Tree.exe: word.o ui.o CinReader.o node.h btree.h driver.cpp
	g++ ui.o word.o CinReader.o driver.cpp -o Tree.exe
	
word.o: word.h word.cpp
	g++ -c word.cpp

ui.o: ui.h ui.cpp
	g++ -c ui.cpp 
	
CinReader.o: CinReader.h CinReader.cpp
	g++ -c CinReader.cpp
closed account (3TXyhbRD)
The line 30 (which doesn't exist) may come from your template class, the compiler generates the class after the template and in this case the generated class is probably placed into your ui.h file (since there is where you use the template, line 15). Have you tested the template separately from ui.h?
Can we also see your node specification?
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Node 
 * Binary tree node
 * 
 * Author: Bianca Migueis
 * Created: 05/07/12
 * Edited: 5/18/12
 *
 */
#pragma once

#include "word.h"

template<class T>
class Node
{
	public:
		/**
		 * Overloaded constructor
		 * sets the data to newData and left and right children to NULL
		 * @param T* new data to create the object
		 */
		Node<T> (T* newData):data(newData), leftChild(NULL), rightChild(NULL){}
		
		/**
		 * Gets the data
		 * @returns T* pointer to data inside the object
		 */
		T* getData ()
		{
			return data;
		}
		
		/**
		 * Set left child
		 * @param Node* new left node
		 */
		void setLeft (Node* newLeft)
		{
			leftChild = newLeft;
		}
		
		/**
		 * Set right child
		 * @param Node* new right node
		 */
		void setRight (Node* newRight)
		{
			rightChild = newRight;
		}
		
		/**
		 * Get Left child
		 * @returns Node<T>*& the left child
		 */
		Node<T>* getLeft () const
		{
			return leftChild;
		}
		
		/**
		 * Get Left child
		 * @returns Node<T>*& the left child
		 */
		Node<T>*& getLeft ()
		{
			return leftChild;
		}
		
		/**
		 * Get Right child
		 * @returns Node<T>*& the right child
		 */
		Node<T>* getRight () const
		{
			return rightChild;
		}
		
		/**
		 * Get Right child
		 * @returns Node<T>*& the right child
		 */
		Node<T>*& getRight ()
		{
			return rightChild;
		}
		
		/**
		 * Overloaded operator >
		 * @returns true if this->data is bigger than src.data, false if not
		 */
		bool operator> (const Node<T>& src)
		{
			return (data > src.data);
		}
		
		/**
		 * Overloaded operator <
		 * @returns true if this->data is smaller than src.data, false if not
		 */
		bool operator< (const Node<T>& src)
		{
			return (data < src.data);
		}
		
		/**
		 * Overloaded operator ==
		 * @returns true if this->data is equal to src.data, false if not
		 */
		bool operator== (const Node<T> src)
		{
			return (data == src.data);
		}
		
		/**
		 * Overloaded operator <<
		 * @returns ostream& formatted to print the node contents
		 */
		friend ostream& operator<< (ostream& outs, const Node<T>& src) 
		{
			outs << src.data;
			
			return outs;
		};
		
	private:
		
		T* data;
		Node* leftChild;
		Node* rightChild;
};
closed account (3TXyhbRD)
btree.h line 13. I don't think that's the issue, however there is a ; after the { } of the constructor.
Topic archived. No new replies allowed.