hay I am using dev c++ and I am having these errors.
[Linker error] undefined reference to `point::point(double, double)'
[Linker error] undefined reference to `point::tostring() const'
[Linker error] undefined reference to `point::point(double, double)'
[Linker error] undefined reference to `point::tostring() const'
[Linker error] undefined reference to `point::point(point const&)'
[Linker error] undefined reference to `point::tostring() const'
[Linker error] undefined reference to `point::operator=(point const&)'
[Linker error] undefined reference to `point::tostring() const'
[Linker error] undefined reference to `point::x() const'
[Linker error] undefined reference to `point::y() const'
[Linker error] undefined reference to `point::~point()'
[Linker error] undefined reference to `point::~point()'
[Linker error] undefined reference to `point::~point()'
[Linker error] undefined reference to `point::~point()'
[Linker error] undefined reference to `point::~point()'
[Linker error] undefined reference to `point::~point()'
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h more undefined references to `point::~point()' follow
32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h ld returned 1 exit status
// Please help me out of these errors.
// please donot refer me to any other post at all. I have read all of the post might be there would be answer in those posts but I am unable to understand that since I am a biggner. Please help me.
Did you implement any of those methods of point?
You only have declarations here, so the compiler doesn't know what to do.
If you have implemented them in another file, you probably forgot to add it to your project.
I did not do anything this is just a bigging of my data structure. This is first program and I am unable do finish with it. I donot know how to use it.
Like I said, a declaration like double x() const; doesn't tell compiler what you want x() to do. You need to add an implementation double x() const { return _x; }. Do this for all of your methods.
tostring is a bit complicated, so I'll show that too:
#include <iostream>
struct example{
int method()//this is the method signature. It tells you how to call this method
{//from here is the implementation. It says what the method actually does.
return 5;
}
};
int main() {
example e;
std::cout << e.method();
}
Note that I left out the copy constructor, assignment operator, and destructor. The compiler will fill those in for you if you don't put them in the class declaration, but if you do put them there you have to write them yourself.
This line in your code means "there is going to be a constructor function, which I will write, that will accept two parameters of type double". Where is that function?
point(const point&);
This line in your code means "there is going to be a constructor function, which I will write, that will accept a single parameters of type point". Where is that function?
~point();
This line in your code means "there is going to be a destructor function, which I will write". Where is that function?
point& operator=(const point&);
And this. Where is the function that you need to write?
double x() const;
And this. Where is the function that you need to write?
double y() const;
And this. Where is the function that you need to write?
string tostring() const;
And this. Where is the function that you need to write?
You created a class, and you said it had all these functions in it, but NONE OF THEM EXIST. C++ is not magic; you have to write functions yourself. If none of that makes any sense to you, classes are too advanced for you and you need to go back to the start.