Reputation: 413
I am getting an error: expected primary-expression before int
when I try to return a 2 values in bool function, I think its a member function error.
bool binaryTreeTraversal::LeafNode(int node)
{
return (binaryTreeTraversal::LeftPtr(int node) == NULL &&
binaryTreeTraversal::RightPtr(int node) == NULL);
}
class binaryTreeTraversal
{
public:
int TreeNodes[2^5];
int size;
binaryTreeTraversal(void);
bool LeafNode(int node);
int RootNode(int node);
int LeftPtr(int node);
int RightPtr(int node);
int length();
int preOrderTraversal(int);
int inOrderTraversal(int);
int postOrderTraversal(int);
};
bool binaryTreeTraversal::LeafNode(int node)
{
return (binaryTreeTraversal::LeftPtr(node) == NULL &&
binaryTreeTraversal::RightPtr(node) == NULL);
}
Upvotes: 6
Views: 91100
Reputation: 39
This is just a simple mistake so you don't need to worry ;-) //wrong code
1: int displayMessage (int num1, int num2)
2: {
3: displayMessage(int num1, int num2);
4: }
Line #3, you have written (int num1, int num2), Both the variables are defined already so you don't need to define again.
Please don't try to define the variables again.
1: int displayMessage (int num1, int num2)enter code here
2: {
3: displayMessage(num1,num2);
4: }
You can go through this for the basic understanding enter link description here
Upvotes: 3
Reputation: 121971
Change:
return (binaryTreeTraversal::LeftPtr(int node) == NULL &&
binaryTreeTraversal::RightPtr(int node) == NULL);
to:
return (binaryTreeTraversal::LeftPtr(node) == NULL &&
binaryTreeTraversal::RightPtr(node) == NULL);
EDIT:
The return type from LeftPtr()
and RightPtr()
is int
:
class binaryTreeTraversal
{
public:
...
bool LeafNode(int node)
{
return (binaryTreeTraversal::LeftPtr(node) == 0 &&
binaryTreeTraversal::RightPtr(node) == 0);
}
};
or:
class binaryTreeTraversal
{
public:
...
bool LeafNode(int node)
{
return (!binaryTreeTraversal::LeftPtr(node) &&
!binaryTreeTraversal::RightPtr(node));
}
};
or as LeftPtr()
and RightPtr()
are not virtual
:
class binaryTreeTraversal
{
public:
...
bool LeafNode(int node)
{
return (!LeftPtr(node) && !RightPtr(node));
}
};
Upvotes: 4
Reputation: 45173
Making this question useful to others: "expected primary-expression" means "I thought you were going to put an expression here."
An expression is an object, a function call, or operators applied to objects and function calls . For example, x + f(y)
is an expression involving variables x
and y
, the function f
and the operator +
.
There are many types of expressions, but the distinction isn't important for the purpose of this error message.
After the open-parenthesis denoting a function call, you are expected to enter an expression, representing the value to pass as a parameter to the function call. But instead, the compiler saw the word int
, which is not a variable or a function or an operator.
Upvotes: 17
Reputation: 294
return (binaryTreeTraversal::LeftPtr(int node) == NULL &&
binaryTreeTraversal::RightPtr(int node) == NULL);
//remove int from bolded part
Upvotes: 1
Reputation: 845
bool binaryTreeTraversal::LeafNode(int node)
{
return ((LeftPtr(node) == NULL) && (RightPtr(node) == NULL));
}
Upvotes: 0
Reputation: 1233
return (binaryTreeTraversal::LeftPtr(int node) == NULL && binaryTreeTraversal::RightPtr(int node) == NULL);
should be
return (binaryTreeTraversal::LeftPtr(node) == NULL && binaryTreeTraversal::RightPtr(node) == NULL);
Upvotes: 0