Hi people,in the assignment I was give the main function and was told to write a class, and the output is supposed to be like this:

BLANK(0,0)
Destination (6.2,16,7)
BLANK (45,0)
Destination (6.2,33.4)
The x coordinate of source is:45
The y coordinate of source is :33.4
The label of point source is:BLANK
The new label of point source is : SOURCE

But my compiler gives me error like:"undefined reference to"to all my functions.Could someone help me please????

#include "Point.h"

Point::Point()
{
   x = 0;
   y = 0;
   l="BLANK";
}


Point::Point( double nx, double ny,string nl )
{
   x=nx;
   y=ny;
   l=nl;
}


void Point::set_x( double nx )
{
   x=nx;
}


void Point::set_y( double ny )
{
   y=ny;
}

void Point::set_label(string nl)
{ l=nl;
}


double Point::get_x() const
{
   return x;
}


double Point::get_y() const
{
   return y;
}

string Point::get_label() const
{ return l;
}


void Point::print() const
{
   cout<<l<<x<<y<<endl;
}





#ifndef POINT_H
#define POINT_H
#include <iostream>
#include <string>
using namespace std;


class Point
{
   public:

      Point();
      Point( double nx, double ny,string nl );

      double get_x() const;
      double get_y() const;
      string get_label()const;

      void set_x( double nx );
      void set_y( double ny );
      void set_label(string label);

      void print() const;

   private:


      double x, y;
      string l;
};

#endif







#include "point.h"
int main(void)
{
  Point source;                                 // default constructor called
  Point destination(6.2, 16.7, "Destination");  // constructor called
	
	source.print();   
	destination.print();
	
	source.set_x(45);
	destination.set_y(33.4);
	
	source.print();
	destination.print();
	
	cout << "The x coordinate of point source is: " 
	<< source.get_x() << endl;
	
	cout << "The y coordinate of point destination is: " 
	     << destination.get_y() << endl;
	
	cout << "The label of point source is: "  << source.get_label() << endl;
	source.set_label("SOURCE");
	
	cout << "The new label of point source is: "  << source.get_label()<< endl;	
	
	cout << "----- Program ends here -----" << endl;
	
	return 0;
}

Line 99: There's an issue with case sensitivity here. In one file you include the header as "Point.h" and in main you include it as "point.h". If that's not the case make sure that your class cpp is getting compiled before your main cpp.

Variable names are case sensitive, but file names are not.
#include <IoStream> would work just as well.

Apologies. I don't know why I was under that impression. Tried it out and as usual Mr. P is right.

Edited 6 Years Ago by jonsca: n/a

I changed the header file name?but it still gives me the same mistake,like unidentified reference...

I changed the header file name?

Yeah, sorry about that one it was an assumption on my part that was false.

How are you compiling these two files? Did you try what I suggested in the other post, to compile the file from lines 1-54 before the main file?

I changed the header file name?but it still gives me the same mistake,like unidentified reference...

In non-English speaking countries, do they actually teach you that spaces after ?,.: etc are not necessary? If so, they were wrong. Always add a space before you start a new sentence.

I'm using the code blocks,and when I compile the class.cpp, he gives me one error unidentified reference to winmain@16.and when I compile the main file,unidentified reference is to every function,I've tried almost everything I know))) but it still wont compile(((

You have selected a Windows GUI application project within the IDE. I haven't used C::B in a while so I don't remember their terminology but you want to select a "console application" instead. Start a new console project and import your code back into it.

This question has already been answered. Start a new discussion instead.