There is a weird syntax error in this code. I don't understand it or any of the errors.
#pragma once
#include <iostream>
class Tree {
public:
Node* root;
void InputTree() {
int n, father;
int nd;
int child;
char dir;
std::cin >> n;
int** tree = new int* [n];
for (int i = 0; i < n; i++) {
std::cin >> nd;
tree[i] = new int[3];
tree[i][0] = nd;
tree[i][1] = -1;
tree[i][2] = -1;
}
for (int i = 0; i < n - 1; i++) {
std::cin >> father >> child >> dir;
if (dir == 'L')
tree[father][1] = child;
else
tree[father][2] = child;
}
Initialize(tree, 0);
}
private:
void Initialize(int** tree, int headIndex) {
if (headIndex != -1) {
root->value = tree[headIndex][0];
root->right_tree->Initialize(tree, tree[headIndex][2]);
root->left_tree->Initialize(tree, tree[headIndex][1]);
}
}
};
class Node {
public:
int value;
Tree* left_tree;
Tree* right_tree;
};
This is the build output of Visual Studio:
Build started...
1>------ Build started: Project: CppMainProject, Configuration: Debug Win32 ------
1>CppMainProject.cpp
1>tstream.h(5,6): error C2143: syntax error: missing ';' before '*'
1>tstream.h(5,6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>tstream.h(5,12): error C2238: unexpected token(s) preceding ';'
1>tstream.h(33,4): error C2065: 'root': undeclared identifier
1>tstream.h(34,4): error C2065: 'root': undeclared identifier
1>tstream.h(35,4): error C2065: 'root': undeclared identifier
1>Done building project "CppMainProject.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========