undeclared identifier

I am trying to define my own class and use them in a program with openCV to create a minimum spanning tree. However, I have no idea why there are problems with my classes. If i comment the bits inside the extra classes and the code that instantiates the objects of my class, it at least starts to run.

At the minute it gives me an error: "Could not find ""C:\xxxx\MST.obj MST.exe was built with /DEBUG:FASTLINK which requires object files for debugging.". It also has a bunch of error messages such as:
- TreeNode undeclared identifier
- Syntax error: missing ; before identifier 'imageTreeNodes'
- 'imageTreeNodes' undeclared identifier
- 'TreeEdge' undeclared identifier
and so on...


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
  #include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <stdio.h>
using namespace cv;

int main()
{
	/*struct edge {
		int weight;
		
	};*/

	/*typedef struct node {
		edge northEdge;
		edge eastEdge;
		edge southEdge;
		edge westEdge;
		int xCoord;
		int yCoord;
	};*/


	Mat imgLeft;
	Mat imgRight;
	imgLeft = imread("C:/Users/Rob McCormack/Documents/Visual Studio 2017/Projects/MST/x64/Debug/image_L.png", IMREAD_GRAYSCALE);	// only inputting string directly for testing purposes
	imgRight = imread("C:/Users/Rob McCormack/Documents/Visual Studio 2017/Projects/MST/x64/Debug/image_R.png", IMREAD_GRAYSCALE);


	if (!imgLeft.data || !imgRight.data)	// error check for the image files
	{
		printf(" Not enough image data \n ");
		return -1;
	}

	int xPixels = imgLeft.rows;
	int yPixels = imgLeft.cols;
	Scalar pixel1Intensity = imgLeft.at<uchar>(0, 0);	//practise
	Scalar pixel2Intensity = imgLeft.at<uchar>(0, 1);

	// create 2D array for tree
	TreeNode imageTreeNodes[544][1024];	// ???????????????? way to use none fixed values

	// edge array, vertical and horizontal
	TreeEdge imageTreeHorizontalEdges[544 - 1][1024 - 1];
	TreeEdge imageTreeVerticalEdges[544 - 1][1024 - 1];

	for (int j = 0; j < yPixels; j++) {	// iterate rows
		for (int i = 0; i < xPixels; i++) {	//iterate columns
			TreeNode thisNode(i,j);
			
			TreeEdge eastEdge;
			TreeEdge southEdge;

			if (i>0) { //set weight of westEdge
				Scalar pixel1Intensity = imgLeft.at<uchar>(i - 1, j);
				Scalar pixel2Intensity = imgLeft.at<uchar>(i, j);

				//float intensityDifference = (pixel1Intensity - pixel2Intensity);
			}

			if (j>0) {	//set weight of northEdge

			}

			thisNode.setEastSouthEdges(eastEdge,southEdge);
			
			imageTreeNodes[j][i] = thisNode;
		}
	}

	waitKey(0);
    return 0;
}

class TreeEdge {

	float weight;
	TreeNode startNode;
	TreeNode endNode;
	
	public: TreeEdge() {

	}

	public: void setWeight(float inputWeight) {
		weight = inputWeight;
	}

	public: float getWeight() {
		return weight;
	}

	public: void setStartNode(TreeNode start) {
		startNode = start;
	}

	public: void setEndNode(TreeNode end) {
		endNode = end;
	}
};

class TreeNode {
	TreeEdge northEdge;
	TreeEdge eastEdge;
	TreeEdge southEdge;
	TreeEdge westEdge;
	int xCoord;
	int yCoord;

	// Default constructor
	public: TreeNode() {

	}


	//constructor 2
	public: TreeNode(int xInput,int yInput) {
		xCoord = xInput;
		yCoord = yInput;
	}

	public: void setEastSouthEdges(TreeEdge east, TreeEdge south) {
		eastEdge = east;
		southEdge = south;
	}

	public: void setAllTreeEdges(TreeEdge north,TreeEdge east,TreeEdge south,TreeEdge west) {
		northEdge = north;
		eastEdge = east;
		southEdge = south;
		westEdge = west;
	}
	
};

Last edited on
closed account (SECMoG1T)
just define your classes out of the main function
The classes are not declared inside the main function.

Any other suggestions?
closed account (SECMoG1T)
try this and post the errors you 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
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
140
141
142
143
144
145
146
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;

///class declarations
class TreeEdge;
class TreeNode;
struct edge;
struct node;

int main()
{
	Mat imgLeft;
	Mat imgRight;
	imgLeft = imread("C:/Users/Rob McCormack/Documents/Visual Studio 2017/Projects/MST/x64/Debug/image_L.png", IMREAD_GRAYSCALE);	// only inputting string directly for testing purposes
	imgRight = imread("C:/Users/Rob McCormack/Documents/Visual Studio 2017/Projects/MST/x64/Debug/image_R.png", IMREAD_GRAYSCALE);


	if (!imgLeft.data || !imgRight.data)	// error check for the image files
	{
		std::cout<<" Not enough image data \n ";
		return -1;
	}

	int xPixels = imgLeft.rows;
	int yPixels = imgLeft.cols;
	Scalar pixel1Intensity = imgLeft.at<uchar>(0, 0);	//practise
	Scalar pixel2Intensity = imgLeft.at<uchar>(0, 1);

	// create 2D array for tree
	TreeNode imageTreeNodes[544][1024];	// ???????????????? way to use none fixed values

	// edge array, vertical and horizontal
	TreeEdge imageTreeHorizontalEdges[544 - 1][1024 - 1];
	TreeEdge imageTreeVerticalEdges[544 - 1][1024 - 1];

	for (int j = 0; j < yPixels; j++) {	// iterate rows
		for (int i = 0; i < xPixels; i++) {	//iterate columns
			TreeNode thisNode(i,j);

			TreeEdge eastEdge;
			TreeEdge southEdge;

			if (i>0) { //set weight of westEdge
				Scalar pixel1Intensity = imgLeft.at<uchar>(i - 1, j);
				Scalar pixel2Intensity = imgLeft.at<uchar>(i, j);

				//float intensityDifference = (pixel1Intensity - pixel2Intensity);
			}

			if (j>0) {	//set weight of northEdge

			}

			thisNode.setEastSouthEdges(eastEdge,southEdge);

			imageTreeNodes[j][i] = thisNode;
		}
	}

	waitKey(0);
    return 0;
}



class TreeNode
{
	TreeEdge northEdge;
	TreeEdge eastEdge;
	TreeEdge southEdge;
	TreeEdge westEdge;
	int xCoord;
	int yCoord;


  public:
    TreeNode() {}// Default constructor

	TreeNode(int xInput,int yInput)//constructor 2
	 :xCoord(xInput),yCoord(yInput){}

    void setEastSouthEdges(TreeEdge east, TreeEdge south)
    {
		eastEdge  = east;
		southEdge = south;
    }

    void setAllTreeEdges(TreeEdge north,TreeEdge east,TreeEdge south,TreeEdge west)
    {
		northEdge = north;
		eastEdge  = east;
		southEdge = south;
		westEdge  = west;
    }

};


class TreeEdge {

	float weight;
	TreeNode startNode;
	TreeNode endNode;

  public:
     TreeEdge() {}

	 void setWeight(float inputWeight)
	 {
		weight = inputWeight;
	 }

	 float getWeight()
	 {
		return weight;
	 }

	void setStartNode(TreeNode start)
	{
		startNode = start;
	}

	void setEndNode(TreeNode end)
	{
		endNode = end;
	}
};

///put this out of main
struct edge
{
    int weight;
};

struct node
{
    edge northEdge;
    edge eastEdge;
    edge southEdge;
    edge westEdge;
    int xCoord;
    int yCoord;
};
Last edited on
Topic archived. No new replies allowed.