template<class> linked list issue

the issue i am having is im creating a template class that needs members of its own class type, as pointers or actual class object members

ie:

1
2
3
4
5
6
template<class TYPE>
class a
{
    a<TYPE> *next,
        *prev;
}


or something to that effect but im getting an error that the member uses a type that is being defined

ie:
error C2460: 'st::bbst<_TYPE,_VAL_TYPE>::next' : uses 'st::bbst<_TYPE,_VAL_TYPE>', which is being defined

PS. ignore the ,_VAL_TYPE part, its to sort with when the user defines a value like an object as the class type
Last edited on
I don't see why you get this error. The code you have posted compiles fine for me if I just put a semicolon at the end of line 6. Could it be that the template argument you are using is causing this problem somehow?
Last edited on
it compiles until you put the code to use and call the constructor for a specified type, ie: a<int> newVar;

thats almost an exact copy of what im doing but mine is using a LOT more members to assemble a tree
Please make sure the code you post have the same problem as the real code. The code you have posted works fine so it is impossible to guess what problems your code that we have never seen have.
i didnt post the entire code because its too long, so heres a segment:

errors:

38x - Error 1 error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'

code:

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
//* searchtree.h
#include <vector>

using namespace std;

namespace st {

	template<class _TYPE, class _VAL_TYPE>
	public ref class bbst
	{
	protected:
		typedef _VAL_TYPE (valfunc) (_TYPE);
	public:

			/* Constructors */

		bbst ();
			//Default Constructor - only works with int/double/unsigned etc, number values as _TYPE

		bbst (valfunc);
			//Overloaded Constructor - required when _TYPE isnt an int/double/unsigned etc
			//@param valfunc - a function that takes _TYPE and returns _VAL_TYPE and _VAL_TYPE must be a number type
			//NOTE: this is how each node gets its number value from strings/objects etc

		bbst<_TYPE, _VAL_TYPE> add_value (_TYPE);
			//bbst<_TYPE, _VAL_TYPE>::add_value - adds the given value to the given tree
			//@param _TYPE - the value to be added to the tree
			//@return *bbst<_TYPE, _VAL_TYPE> *- the node that was added to the tree

		void add_value (_TYPE[], int);
			//bbst<_TYPE, _VAL_TYPE>::add_value - adds the given array to the tree
			//@param _TYPE[] - the array to add to the tree
			//@param int - from 0 - what index should be added to the tree

		void add_value (vector<_TYPE>&);
			//bbst<_TYPE, _VAL_TYPE>::add_value - adds the given vector to the tree
			//@param vector<_TYPE>& - the vector to be added to the tree

			/* Destructors */

		void delete_node ();
			//bbst<_TYPE, _VAL_TYPE>::delete_node - deletes the given node

		void delete_tree ();
			//bbst<_TYPE, _VAL_TYPE>::delete_tree - deletes the given tree

			/* Accessor Functions */

		_TYPE get_value ();
			//bbst<_TYPE, _VAL_TYPE>::get_value - gets the value of the given node

		unsigned int get_size ();
			//bbst<_TYPE, _VAL_TYPE>::get_size - gets the size of the given node (size of its children branches + itself)

		unsigned int get_depth ();
			//bbst<_TYPE, _VAL_TYPE>::get_depth - gets the depth of the given node (how many layers down from 0 it is)

			/* Mutator Functions */

		void set_value (_TYPE);
			//bbst<_TYPE, _VAL_TYPE>::set_value - sets the value of the given node
			//@param _TYPE - the new value of the node

		void set_autoRefresh (bool);
			//bbst<_TYPE, _VAL_TYPE>::set_autoRefresh - sets the autoRefresh member, if true every time a node is moved it will check the tree if it should be refreshed
			//@param bool - the new value of autoRefresh

			/* Utility Functions */

		bbst<_TYPE, _VAL_TYPE> find (_TYPE);
			//bbst<_TYPE, _VAL_TYPE>::find - searches the tree for the given value
			//@param _TYPE - the value to search for
			//@return *bbst<_TYPE, _VAL_TYPE> *- the node with the closest given value

		void refresh_tree ();
			//bbst<_TYPE, _VAL_TYPE>::refresh_tree - refreshes the given tree (adjusts branches to minimize the search calls)

	protected:
		bbst (_TYPE);
			//Overloaded Constructor
			//@param _TYPE - the value to be used for the new node

		~bbst ();
			//Default Destructor

		void remove (bool);
			//bst<_TYPE, _VAL_TYPE>::remove - removes the given node from the tree
			//@param bool - consider twins? if true it removes the node from the list of twins, if false it removes the node but twins remain attached

		void insert (bbst<_TYPE, _VAL_TYPE>*);
			//bst<_TYPE, _VAL_TYPE>::insert - inserts the given node at the given location
			//@param bst<_TYPE, _VAL_TYPE> - the location to insert the given node

		void rebalance ();
			//bbst<_TYPE, _VAL_TYPE>::rebalance - rebalances the given node

		void update_depth ();
			//bbst<_TYPE, _VAL_TYPE>::update_depth - updates the depth of every node from the given branch

		_TYPE userValue;

		_VAL_TYPE value;

		bool autoRefresh;

		unsigned int size,
			depth;

		valfunc val_update;

		bbst *parent,
			*left,
			*right,
			*sibling,
			*root,
			*next,
			*prev,
			*nextLeaf,
			*prevLeaf,
			*nextTwin,
			*prevTwin;
	};
}


the definitions are in the same file, just not posting them here because its far too long
Last edited on
I have 2 questions to this code:

1. Do you get the error when you compile the class or when you instantiate it?

2. What's the difference between _VAL_TYPE and _TYPE? is _TYPE supposed to be an std container? Please tell me how you instantiate this class template.
_TYPE is the type that each node is storinng
_VAL_TYPE is the way that each is sorted (ie: _TYPE is a string, it sorts via _VAL_TYPE)

st::bbst<int, int> intbst; is an example of creating a normal tree that just uses its normal value as the value to be sorted
st::bbst<std::string, int> stringbst (StringToInt) is an example of a string type tree where StringToInt is how the search tree determines the value of the node: int StringToInt (std::string);

it gets some of these errors when instaniating, some when not, i think its probably that it doesnt check the methods inside the class until it is instantiated, it only gives errors for the members declared inside the class but not the definitions

if thats still not enough to see where the error might be just tell me and ill upload the header file
Last edited on
Does the error come within the class definition or some implementation? if within the definition, could you please point out at which line? if at the implementation, could you please post the code, at which the error occurs?
I just noticed something, man! why is the destructor and some constructor protected? is this allows in C++/CLI? it doesn't compile here with me!!!
This code compiles fine with me:

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
132
133
134
135
136
137
138
139
//* searchtree.h
#include <vector>

using namespace std;
namespace st {

    template<class _TYPE, class _VAL_TYPE>
    class bbst
    {
    protected:
        typedef _VAL_TYPE (valfunc) (_TYPE);
    public:

            /* Constructors */

        bbst ();
            //Default Constructor - only works with int/double/unsigned etc, number values as _TYPE

        bbst (valfunc);
            //Overloaded Constructor - required when _TYPE isnt an int/double/unsigned etc
            //@param valfunc - a function that takes _TYPE and returns _VAL_TYPE and _VAL_TYPE must be a number type
            //NOTE: this is how each node gets its number value from strings/objects etc

        bbst<_TYPE, _VAL_TYPE> add_value (_TYPE);
            //bbst<_TYPE, _VAL_TYPE>::add_value - adds the given value to the given tree
            //@param _TYPE - the value to be added to the tree
            //@return *bbst<_TYPE, _VAL_TYPE> *- the node that was added to the tree

        void add_value (_TYPE[], int);
            //bbst<_TYPE, _VAL_TYPE>::add_value - adds the given array to the tree
            //@param _TYPE[] - the array to add to the tree
            //@param int - from 0 - what index should be added to the tree

        void add_value (vector<_TYPE>&);
            //bbst<_TYPE, _VAL_TYPE>::add_value - adds the given vector to the tree
            //@param vector<_TYPE>& - the vector to be added to the tree

            /* Destructors */

        void delete_node ();
            //bbst<_TYPE, _VAL_TYPE>::delete_node - deletes the given node

        void delete_tree ();
            //bbst<_TYPE, _VAL_TYPE>::delete_tree - deletes the given tree

            /* Accessor Functions */

        _TYPE get_value ();
            //bbst<_TYPE, _VAL_TYPE>::get_value - gets the value of the given node

        unsigned int get_size ();
            //bbst<_TYPE, _VAL_TYPE>::get_size - gets the size of the given node (size of its children branches + itself)

        unsigned int get_depth ();
            //bbst<_TYPE, _VAL_TYPE>::get_depth - gets the depth of the given node (how many layers down from 0 it is)

            /* Mutator Functions */

        void set_value (_TYPE);
            //bbst<_TYPE, _VAL_TYPE>::set_value - sets the value of the given node
            //@param _TYPE - the new value of the node

        void set_autoRefresh (bool);
            //bbst<_TYPE, _VAL_TYPE>::set_autoRefresh - sets the autoRefresh member, if true every time a node is moved it will check the tree if it should be refreshed
            //@param bool - the new value of autoRefresh

            /* Utility Functions */

        bbst<_TYPE, _VAL_TYPE> find (_TYPE);
            //bbst<_TYPE, _VAL_TYPE>::find - searches the tree for the given value
            //@param _TYPE - the value to search for
            //@return *bbst<_TYPE, _VAL_TYPE> *- the node with the closest given value

        void refresh_tree ();
            //bbst<_TYPE, _VAL_TYPE>::refresh_tree - refreshes the given tree (adjusts branches to minimize the search calls)

        bbst (_TYPE);
            //Overloaded Constructor
            //@param _TYPE - the value to be used for the new node

        ~bbst ();
            //Default Destructor

        void remove (bool);
            //bst<_TYPE, _VAL_TYPE>::remove - removes the given node from the tree
            //@param bool - consider twins? if true it removes the node from the list of twins, if false it removes the node but twins remain attached

        void insert (bbst<_TYPE, _VAL_TYPE>*);
            //bst<_TYPE, _VAL_TYPE>::insert - inserts the given node at the given location
            //@param bst<_TYPE, _VAL_TYPE> - the location to insert the given node

        void rebalance ();
            //bbst<_TYPE, _VAL_TYPE>::rebalance - rebalances the given node

        void update_depth ();
            //bbst<_TYPE, _VAL_TYPE>::update_depth - updates the depth of every node from the given branch

        _TYPE userValue;

        _VAL_TYPE value;

        bool autoRefresh;

        unsigned int size,
            depth;

        valfunc val_update;

        bbst *parent,
            *left,
            *right,
            *sibling,
            *root,
            *next,
            *prev,
            *nextLeaf,
            *prevLeaf,
            *nextTwin,
            *prevTwin;
    };
}
using namespace st;

template<class _TYPE, class _VAL_TYPE>
bbst<_TYPE, _VAL_TYPE>::bbst()
{

}
template<class _TYPE, class _VAL_TYPE>
bbst<_TYPE, _VAL_TYPE>::~bbst()
{

}

int main(int argc, char** argv)
{
    st::bbst<int, int> x;
}
The errors are all the same:
lines 92, 114-124, 507 have this error:
error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'

the destructor is protected because it dissasembles the whole tree below a given node via recursion
the constructor is protected because the public constructors create a whole new tree
Try to use the code I wrote. Does this compile? (Of course, add the CLI stuff, like public ref prefixes for the class name).
I got it man!!!!

Just use managed pointers and it will work!!!! use ^ instead of *.
that compiles for me as well, idk whats wrong but i cant see any differences other than the protected: being removed and the <_TYPE, _VAL_TYPE> being removed on the bbst and after changing them im still getting the errors with my code

heres what i get:

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
1
1>  searchtree.cpp
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(93): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>          c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(125) : see reference to class template instantiation 'st::bbst<_TYPE,_VAL_TYPE>' being compiled
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(114): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(115): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(116): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(117): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(118): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(119): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(120): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(121): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(122): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(123): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(124): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
1>c:\users\debbie\desktop\documents\visual studio 2010\projects\searchtree\searchtree\searchtree.h(507): error C3699: '*' : cannot use this indirection on type 'st::bbst<_TYPE,_VAL_TYPE>'
1>          compiler replacing '*' with '^' to continue parsing
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Like I said, change to handles "^" rather than pointers "*" and it will compile.

Cheers :)
oh derp :/
i didnt actually read all that but i see the ^s now
how do you reference an object via the handle?
i cant find any tutorials on it
Topic archived. No new replies allowed.