Assistance needed desperately :(

I just started out with C++, really a beginner here. And is really desperate for help now. Would really appreciate if any kind souls can help. Really sorry, but here is a long list of error

Compilation error


Assn3.cpp: In function ‘void option1()’:
Assn3.cpp:137: error: no matching function for call to ‘Point2D::Point2D()’
Point2D.h:20: note: candidates are: Point2D::Point2D(int, int)
Point2D.h:12: note:                 Point2D::Point2D(const Point2D&)
Assn3.cpp:148: error: no match for ‘operator>>’ in ‘c >> * p2d’
/usr/include/c++/4.4/istream:119: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:123: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:130: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:166: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:170: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:173: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:177: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:180: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:188: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:193: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:197: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:202: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:206: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:210: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:214: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:238: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
Assn3.cpp:149: error: ‘p2dItems’ was not declared in this scope
Assn3.cpp:159: error: no matching function for call to ‘Point3D::Point3D()’
Point3D.h:17: note: candidates are: Point3D::Point3D(int, int, int)
Point3D.h:11: note:                 Point3D::Point3D(const Point3D&)
Assn3.cpp:170: error: no match for ‘operator>>’ in ‘c >> * p3d’
/usr/include/c++/4.4/istream:119: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:123: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:130: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:166: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:170: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:173: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:177: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:180: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:188: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:193: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:197: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:202: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:206: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:210: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/istream:214: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]






And here part of the source 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <fstream>
#include <sstream>
#include <set>

#include "Point2D.h"
#include "Point3D.h"
#include "Line2D.h"
#include "Line3D.h"
#include "MyTemplates.h"



using namespace std;
									// FilterCriteria enum
enum FilterCriteria 
{
	POINT2D,POINT3D,LINE2D,LINE3D,	
};

									// overload << to print FilterCriteria
ostream& operator<<(ostream& os,FilterCriteria fc) 
{
    	switch(fc) 
	{
    		case POINT2D:
        	return os << "Point2D";

    		case POINT3D:
        	return os << "Point3D";

    		case LINE2D:
        	return os << "Line2D";

    		case LINE3D:
        	return os << "Line3D";
    }
}

									// SortCriteria enum
enum SortCriteria 
{
    Pt1,Pt2,Length,
};

									// overload << operator for easy printing of sort criteria
ostream& operator<<(ostream& os,SortCriteria sc) 
{
    	switch(sc) 
	{
    		case Pt1:
        	return os << "Pt. 1’s (x, y) values";

    		case Pt2:
        	return os << "Pt. 2’s (x, y) values";

    		case Length:
        	return os << "Length";
    	}
}

									// sort order enum
enum SortOrder 
{
    	ASC,  DESC, 							// Ascending & Descending   
};

									// overload << operator for printing of SortOrder
ostream& operator<<(ostream& os,SortOrder so) 
{
   
    	switch(so) 
	{
    		case Pt1:
        	return os << "ASC (Ascending order)";

    		case Pt2:
        	return os << "DESC (Descending order)";
    	}
}

int choice; 
int recordCount; 
string filterIn;  					// all other menus, user input
string inputFile, outputFile; 				// file to read from , file to write to
             				
    
FilterCriteria fc = POINT2D; 				// filter criteria
SortCriteria sc = Pt1;  				// sorting criteria
    
SortOrder so= ASC;  					// sort order
ifstream ifs;  						// input file stream
ofstream ofs;   					// output file stream
    
    							// collections, used set for the purpose of uniqueness.
//set<Point2D> p2dItems;
//set<Point3D> p3dItems;
//set<Line2D> l2dItems;
//set<Line3D> l3dItems;

void mainMenu()								//Function before main 
{
	cout<<"\n"<<"Welcome to Assn3 program!"<<"\n"<<endl<<
   
      	"1)	Read in data"<<endl<<
      	"2)	Specify filtering criteria (current : Point2D)"<<endl<<
      	"3)	Specify sorting criteria (current : x-ordinate)"<<endl<<   		
      	"4)	Specify sorting order (current : ASC)"<<endl<<
	"5)	View data"<<endl<<
	"6)	Store data"<<endl<<
	"\n"<<"Please enter your choice :";
	cin>>choice;

}


void option1()
{

	cout << "Please enter filename: ";	
	cin >> inputFile;
      	ifs.open(inputFile.c_str(),std::ios::in);
        recordCount = 0;
            
	while( ifs.good() ) 
	{
        	string className;
                string str;
                getline( ifs, className, ',' );
                getline(ifs,str,'\n');

                if (className == "Point2D") 
		{
                    	stringstream cords(str);
                    	Point2D *p2d = new Point2D();
                    	string s;

                    	while(cords.good()) 
			{
                        	getline(cords,s,']');

                        	if (s.size() > 0) 
				{
                            		s = s.substr(1);
                            		stringstream c(s);
                            		c >> *p2d;
                            		p2dItems.insert(*p2d);
                            		recordCount++;
                        	}
                    	}
                } 


		else if (className == "Point3D") 
		{
                    	stringstream cords(str);
                  	Point3D *p3d = new Point3D();
                    	string s;
                    
			while(cords.good()) 
			{
				getline(cords,s,']');
		
			  	if (s.size() > 0) 
				{
			        	s = s.substr(1);
			             	stringstream c(s);
			               	c >> *p3d;
                            		p3dItems.insert(*p3d);
                        		recordCount++;
                        	}
                    	} 
                } 
	

		else if (className == "Line2D") 
		{
               		stringstream cords(str);
                    	Line2D *l2d = new Line2D();
                    	cords >> *l2d;
                    	l2dItems.insert(*l2d);
                    	recordCount++;
                } 
	

		else if (className == "Line3D") 
		{
		    	stringstream cords(str);
		       	Line3D *l3d = new Line3D();
		     	cords >> *l3d;
			l3dItems.insert(*l3d);
		        recordCount++;
		}
            
	}
            cout << recordCount << " records read in successfully" << endl;
            cout << "Going back to main menu!" << endl;
            
}


void option2()
{
	FilterCriteria fc = POINT2D; 		
	cout << "Specifying Filtering Criteria (Current: " <<fc << ")" << endl;
      	cout << endl;
      	cout << "a)\t" << POINT2D << endl;
    	cout << "b)\t" << POINT3D << endl;
       	cout << "c)\t" << LINE2D << endl;
       	cout << "d)\t" << LINE3D << endl;
       	cout << "Please enter your criteria (a-d): ";
       	cin >> filterIn;

     	switch(filterIn[0]) 
	{
           	case 'a':
                fc = POINT2D;
                break;
            
		case 'b':
                fc = POINT3D;
                break;
            
		case 'c':
                fc = LINE2D;
                break;
            
		case 'd':
                fc = LINE3D;
                break;
            
		default:
                cout << "Bad input!Use a-d next time" << endl;
                break;
            }
            cout << "Filtering criteria successfully set to " << fc << endl;
}


void option3()
{
	cout << "Specifying Sorting Criteria (Current: " <<sc <<")"<<endl; // header message
      	cout << endl;

     	// print options
     	cout << "a)\t" << Pt1 << endl;
  	cout << "b)\t" << Pt2 << endl;
  	cout << "c)\t" << Length << endl;
   	cout << "Please enter your criteria (a - c): ";
     	cin >> filterIn; // read input

   	switch(filterIn[0]) 		// get first character and evaluate it
	{ 
     		case 'a':
   		sc = Pt1;
      		break;

     		case 'b':
                sc = Pt2;
                break;

        	case 'c':
                sc = Length;
                break;

    		default:
                cout << "Bad Input. Required a - c!" << endl;
                break;
	}
            
	cout << "Sorting criteria successfully set to " << sc << endl; 		// success message
}


void option4()									// specify sorting order
{
	 
	
            
	cout << "Specifying Sorting Order (Current: " <<so <<")"<<endl; 	// header message           
	cout << endl;
            
	// print options
            
	cout << "a)\t" << ASC << endl;
	cout << "b)\t" << DESC << endl;
	cout << "Please enter your order (a or b): "; 				// prompt for input            
	cin >> filterIn; // read user input

            
	switch(filterIn[0]) 							// get first character and evaluate that
	{ 							
      		case 'a':
                so = ASC;
                break;

            	case 'b':
                so = DESC;
                break;

            	default:
                cout << "Bad Input. Required a or b!" << endl;
	}
}


continue from above

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
147
148
149
150
151
152
153
154
155
156

void option5()									// view the data
{
	
            									//print current options
	cout << "Filtering Criteria: " << fc << endl;
     	cout << "Sorting Criteria : " << sc << endl;
     	cout << "Sorting Order: " << so << endl;
     	cout << endl;
            
	switch(fc) 								// evaluate current fc and print appropriate class data
	{ 
            	case POINT2D:
                cout << " X     Y      Dist. Fr Origin" << endl;
                cout << "------------------------------" << endl;

                for (set<Point2D>::iterator itr = p2dItems.begin(); itr != p2dItems.end(); itr++) 
		{
                    	cout << const_cast<Point2D&>(*itr);
                }
                break;

            	case POINT3D:
                cout << " X   Y    Z      Dist. Fr Origin" << endl;
                cout << "----------------------------------" << endl;

                for (set<Point3D>::iterator itr = p3dItems.begin(); itr != p3dItems.end(); itr++) 
		{
                    	cout << const_cast<Point3D&>(*itr);
                }
                break;

            	case LINE2D:
                cout << " P1-X  P1-Y     P2-X  P2-Y  Length" << endl;
                cout << "-----------------------------------" << endl;

                for (set<Line2D>::iterator itr = l2dItems.begin(); itr != l2dItems.end(); itr++) 
		{
               		cout << const_cast<Line2D&>(*itr);
                }
                break;

            	case LINE3D:
                cout << " P1-X  P1-Y  P1-Z  P2-X  P2-Y  P2-Z  Length" << endl;
                cout << "-----------------------------------------------" << endl;
                for (set<Line3D>::iterator itr = l3dItems.begin(); itr != l3dItems.end(); itr++) 
		{
                    	cout << const_cast<Line3D&>(*itr);
                }
                break;            
	}
}

void option6()									// store data to file
{
	cout << "Please enter file name: "; 					// prompt file name
      	cin >> outputFile;  							//read filename
       	ofs.open(outputFile.c_str(),std::ios::out); 				// try to open filename
    	
	if (!ofs.good()) 							// if all is not well
	{  							
      		cout << "Could not create " << outputFile << "!" << endl; 	// tell user it went bad, opening the output file
       		break;
       	}
            // otherwise print what we have so far, into the file output stream
      	ofs << "Filtering Criteria: " << fc << endl;
   	ofs << "Sorting Criteria : " << sc << endl;
     	ofs << "Sorting Order: " << so << endl;
     	cout << endl;

     	switch(fc)						// and based on the current filter creteria, print the class data to into the file 
	{  
        	case POINT2D:
                ofs << " X     Y      Dist. Fr Origin" << endl;
                ofs << "------------------------------" << endl;
                for (set<Point2D>::iterator itr = p2dItems.begin(); itr != p2dItems.end(); itr++) 
		{
                    	ofs << const_cast<Point2D&>(*itr);
                }
                break;

            	case POINT3D:
                ofs << " X   Y    Z      Dist. Fr Origin" << endl;
                ofs << "----------------------------------" << endl;
                for (set<Point3D>::iterator itr = p3dItems.begin(); itr != p3dItems.end(); itr++) 
		{
                    	ofs << const_cast<Point3D&>(*itr);
                }
                break;
	
            	case LINE2D:
                ofs << " P1-X  P1-Y     P2-X  P2-Y  Length" << endl;
                ofs << "-----------------------------------" << endl;
                for (set<Line2D>::iterator itr = l2dItems.begin(); itr != l2dItems.end(); itr++) 
		{
                    	ofs << const_cast<Line2D&>(*itr);
                }
                break;

           	case LINE3D:
                ofs << " P1-X  P1-Y  P1-Z  P2-X  P2-Y  P2-Z  Length" << endl;
                ofs << "-----------------------------------------------" << endl;
                for (set<Line3D>::iterator itr = l3dItems.begin(); itr != l3dItems.end(); itr++) 
		{
                    	ofs << const_cast<Line3D&>(*itr);
                }
                break;
          
	}
	ofs.close(); // close file
  	//break;
        //default:  // unknown option
        cout << "Unsupported option. Please select 0 - 6";
}

int main() 
{
    
    	
	while (choice != 7) 
	{
									//Function call
        	mainMenu();

       
        	switch (choice) 
		{
		case 1:
                	option1();					//Function call
                	break;
		
            	case 2:
                	option2();					//Function call
                	break;

            	case 3:
                	option3();					//Function call
                	break;

            	case 4:
                	option4();					//Function call
                	break;

		case 5:
                	option5();					//Function call
                	break;

		case 6:
                	option6();					//Function call
                	break;

	
        	}

    	}
}
Look at what your compiler errors are telling you.

The first one is telling you that, at line 137 of assn3.cpp, you're trying to call Point2D::Point2D() with no arguments, and that you haven't defined method with that name and arguments (in this case, it's a constructor). It's also helpfully telling you that you have defined a constructor Point2D::Point2D(int, int) - is that what you meant to call?

Compiler errors can sometimes be a bit cyptic and misleading, but a lot of the time they tell you exactly what the problem is and where it is. You should pay attention to them.
Last edited on
Thanks, I took a whole night and have created a constructor in my class with no return type. Now managed to bring the errors down to the following..

/tmp/cceGUEEB.o: In function `option1()':
Assn3.cpp:(.text+0x3cb): undefined reference to `Point2D::Point2D()'
Assn3.cpp:(.text+0x592): undefined reference to `Point3D::Point3D()'
Assn3.cpp:(.text+0x759): undefined reference to `Line2D::Line2D()'
Assn3.cpp:(.text+0x809): undefined reference to `Line3D::Line3D()'
collect2: ld returned 1 exit status


Though I've // quite a few problems with the << and >> operators
Recheck your structure. I pretty sure some of defined functions are missing.
Please look at what the compiler errors are telling you.

Example :
Assn3.cpp:(.text+0x3cb): undefined reference to `Point2D::Point2D()


You called Point2D::Point2D() at somewhere in your code (Assn3.cpp), but maybe Point2D::Point2D() function doesn't have any code.
Last edited on
Topic archived. No new replies allowed.