Question:
Why does my C++ compiler keep saying "expected constructor, destructor, or type conversion before * token"?
?
2009-06-10 10:51:12 UTC
I keep getting the following error:

---
Tree.h:92: error: expected constructor, destructor, or type conversion before â*â token
---

But I can't find anything syntactically wrong with the code. I don't think that the error has anything to do with the code above or below it either, because when I delete it, everything complies fine.

Below is the function definition:

---
091 : template // Key, Value
092 : Node* Tree::findNodeRecursively(Node* node, K key) {
093 : - if(node == 0)
094 : - - return 0;
095 :
096 : - int result = compare(node->key_, key);
097 :
098 : - if(result == 0)
099 : - - return node;
100 : - else if(result == -1)
101 : - - return findNodeRecursively(node->left_, key);
102 : - else
103 : - - return findNodeRecursively(node->right_, key);
104 :}
---

The class deceleration is:

---
template // Key, Value
class Tree {
- public:
- Tree(int (*compare)(K, K));
- //~Tree();
- void insertValue(K key, V* value);
- V* findValue(K key);
- void deleteValue(K key);
- int getDepth() const; // 1-based
- void debug() const;

private:
- class Node {
- public:
- - Node(K key, V* value) : key_(key), value_(value) { }
- - K key_;
- - V* value_;
- - Node* left_;
- - Node* right_;
- };
- void insertRecursively(Node* node, K key, V* value);
- Node* findNodeRecursively(Node* node, K key);
- int getDepthRecursively(Node* node) const;
- Node* root_;
- int (*compare_)(K, K);
};
---

I'm new to C++, so feel free to critique as well :)
Five answers:
videobobkart
2009-06-10 15:20:37 UTC
I got it to compile by changing this line:



Node* Tree::findNodeRecursively(Node* node, K key) {



to this:



class Tree::Node* Tree::findNodeRecursively(Node* node, K key) {
anonymous
2016-03-17 14:33:30 UTC
I thought rock was dead in the Eighties, I hated Hair Bands and Punk and Disco. The 90s proved me wrong when I heard Nirvana, Pearl Jam, Stone Temple Pilots and Sound Garden. It seems like rock might be dying again now that those bands are gone but it just depends on what you like. It you don't like the new stuff at the time then it will seem like rock is dying. Of course music has to change or we would all be sick of the same old thing. It is harder these days to be a supergroup because nobody can match record sales of the past. People these days just download the music they want. Alot of the time it is just one song and not the whole album. In the 70s I would buy an album not for one song but for all of them. Also for the cover art of the album and what it had to say. Younger people today don't have the feeling of owning an actual physical collection. They just put music into a computer and thats it. Rock will never die because there will always be that young musician out there that is good enough to come up with something new but use the influences of the past to do something like Kurt Cobain did.
lansingstudent09101
2009-06-10 11:26:51 UTC
rather than making the node class public, make the classes or functions friends.
Jill
2009-06-10 11:06:21 UTC
Why is class node private? make it public or else the constructor will also be private.
ITConsulting
2009-06-10 11:01:38 UTC
I think because you are trying to access a private class.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...