Hello,
I have problems with this simple program:
#include<iostream>
#include<fstream>
class Point {
public:
int x,y;
Point(int x=0,int y=0)
{ this->x=x; this->y=y; }
~Point() {}
};
class Curve {
public:
virtual int getValue(const double t)=0;
virtual ~Curve();
};
class LineCurve: public Curve {
private:
Point data[2];
double dt;
public:
int getValue(const double dt) { return 0; }
~LineCurve() {}
};
int main(void)
{
Curve* ptr;
ptr=new LineCurve;
return 0;
}
Wenn I comment ptr=new LineCurve; line out, then the code compiles.
Otherweis I get link errors. What is wrong here? It should be something
to do with virtuals, but I couldn't find it out?
Best regards.
Erdal Mutlu 14 1307
Erdal MUTLU wrote: Hello,
I have problems with this simple program:
#include<iostream> #include<fstream> class Point { public: int x,y; Point(int x=0,int y=0) { this->x=x; this->y=y; } ~Point() {} }; class Curve { public: virtual int getValue(const double t)=0; virtual ~Curve(); };
class LineCurve: public Curve { private: Point data[2]; double dt; public: int getValue(const double dt) { return 0; } ~LineCurve() {} };
int main(void) { Curve* ptr;
ptr=new LineCurve; return 0; }
Wenn I comment ptr=new LineCurve; line out, then the code compiles. Otherweis I get link errors.
Well. Usually the linker tells you what's wrong
What is wrong here?
You didn't read the error message.
If I cut&paste your program into VC++, the linker tells me:
error LNK2001: unresolved external symbol "public: virtual __thiscall Curve::~Curve(void)
So it says: Hay buddy. I cannot find an implementation for the destructor of Curve.
Looking up your code, the Code is right. You declared a destructor but nowhere
there is an implementation for it.
Changr to:
class Curve {
public:
virtual int getValue(const double t)=0;
virtual ~Curve() {}
};
^
|
*
--
Karl Heinz Buchegger kb******@gascad.at
Karl Heinz Buchegger wrote:
error LNK2001: unresolved external symbol "public: virtual __thiscall Curve::~Curve(void)
So it says: Hay buddy. I cannot find an implementation for the destructor of Curve. Looking up your code, the Code is right. You declared a destructor but nowhere
.... the Linker is ....
--
Karl Heinz Buchegger kb******@gascad.at
hi! error LNK2001: unresolved external symbol "public: virtual __thiscall
Curve::~Curve(void) So it says: Hay buddy. I cannot find an implementation for the destructor
of Curve. Looking up your code, the Code is right. You declared a destructor but
nowhere there is an implementation for it.
i do have a question regarding this. why is an implementation of the
destructor needed, when it's never called anyway? the object is allocated on
free memory but never release with delete, so no destructor is called!? i
think i'm getting something terribly wrong, but what?
thanks.
regards,
sev
Karl Heinz Buchegger wrote: Well. Usually the linker tells you what's wrong
What is wrong here?
You didn't read the error message. If I cut&paste your program into VC++, the linker tells me:
error LNK2001: unresolved external symbol "public: virtual __thiscall Curve::~Curve(void)
So it says: Hay buddy. I cannot find an implementation for the destructor of Curve. Looking up your code, the Code is right. You declared a destructor but nowhere there is an implementation for it.
Changr to:
class Curve { public: virtual int getValue(const double t)=0; virtual ~Curve() {} };
^ | *
Thank you!
Best regards.
Erdal Mutlu
Severin Ecker wrote: hi!
error LNK2001: unresolved external symbol "public: virtual __thiscall
Curve::~Curve(void)
So it says: Hay buddy. I cannot find an implementation for the destructor
of Curve.
Looking up your code, the Code is right. You declared a destructor but
nowhere
there is an implementation for it.
i do have a question regarding this. why is an implementation of the destructor needed, when it's never called anyway? the object is allocated on free memory but never release with delete, so no destructor is called!? i think i'm getting something terribly wrong, but what? thanks.
regards, sev
Hi,
this code is only a part of some bigger class. That is why you do not
see where objects of type Curve are deleted. I had to localize the
problem, that is why the code is somewhat uncomplete.
Best regrads.
Erdal Mutlu
Severin Ecker wrote: hi!
error LNK2001: unresolved external symbol "public: virtual __thiscall Curve::~Curve(void) So it says: Hay buddy. I cannot find an implementation for the destructor
of Curve. Looking up your code, the Code is right. You declared a destructor but nowhere there is an implementation for it.
i do have a question regarding this. why is an implementation of the destructor needed,
Because the compiler has set things up that in the final executable
there has to be a destructor :-)
when it's never called anyway? the object is allocated on free memory but never release with delete, so no destructor is called!?
Hmm. Good question.
The only thing I can think of is:
If you don't define a destructor on your own, then the compiler will
generate one for you. So every class always has a destructor. Since it
absolutely makes no sense to have no destructor at all, it could be
a decission of the compiler writer to set things up such that such
a case is reported.
--
Karl Heinz Buchegger kb******@gascad.at
Severin Ecker posted: i do have a question regarding this. why is an implementation of the destructor needed, when it's never called anyway? the object is allocated on free memory but never release with delete, so no destructor is called!? i think i'm getting something terribly wrong, but what? thanks.
If the destructor is never to be called, then don't declare it in the class.
As for declaring it in the class and then not defining it, why is this a
problem although even the destructor is never called? Because the C++
Standard says so!
-JKop
Karl Heinz Buchegger wrote in news:40***************@gascad.at in
comp.lang.c++: Severin Ecker wrote: hi!
> error LNK2001: unresolved external symbol "public: virtual > __thiscall Curve::~Curve(void) > > So it says: Hay buddy. I cannot find an implementation for the > destructor of Curve. > Looking up your code, the Code is right. You declared a destructor > but nowhere > there is an implementation for it.
i do have a question regarding this. why is an implementation of the destructor needed,
Because the compiler has set things up that in the final executable there has to be a destructor :-)
when it's never called anyway? the object is allocated on free memory but never release with delete, so no destructor is called!?
Hmm. Good question.
If new throws std::bad_alloc then the destructor will be called,
So the declared destructor is required by the language.
Rob.
-- http://www.victim-prime.dsl.pipex.com/
Rob Williscroft wrote:
If new throws std::bad_alloc then the destructor will be called, So the declared destructor is required by the language.
Thanks for clearification.
--
Karl Heinz Buchegger kb******@gascad.at
Rob Williscroft wrote:
If new throws std::bad_alloc then the destructor will be called, So the declared destructor is required by the language.
thanks for the fast and clear answer!
regards,
sev
You need to provide a body for the ~Curve() destructor. All the
explanations
I've seen for the requirement so far are wrong, you need it because it is
declared
as virtual, that puts an obligation on the class designer to provide a
destructor, whether
or not it is called in the executable.
dave
"Erdal MUTLU" <em****@fonts.de> wrote in message
news:2i************@uni-berlin.de... Hello,
I have problems with this simple program:
#include<iostream> #include<fstream> class Point { public: int x,y; Point(int x=0,int y=0) { this->x=x; this->y=y; } ~Point() {} }; class Curve { public: virtual int getValue(const double t)=0; virtual ~Curve(); };
class LineCurve: public Curve { private: Point data[2]; double dt; public: int getValue(const double dt) { return 0; } ~LineCurve() {} };
int main(void) { Curve* ptr;
ptr=new LineCurve; return 0; }
Wenn I comment ptr=new LineCurve; line out, then the code compiles. Otherweis I get link errors. What is wrong here? It should be something to do with virtuals, but I couldn't find it out?
Best regards. Erdal Mutlu
Karl Heinz Buchegger wrote: If you don't define a destructor on your own, then the compiler will generate one for you. So every class always has a destructor. Since it absolutely makes no sense to have no destructor at all, it could be a decission of the compiler writer to set things up such that such a case is reported.
The formalism is 3.2/2: "a virtual member function is used if it is not
pure" and 3.2/3: "Every program shall contain exactly one definition of
every non-inline function or object that is used in that program."
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
Pete Becker wrote: Karl Heinz Buchegger wrote: If you don't define a destructor on your own, then the compiler will generate one for you. So every class always has a destructor. Since it absolutely makes no sense to have no destructor at all, it could be a decission of the compiler writer to set things up such that such a case is reported.
The formalism is 3.2/2: "a virtual member function is used if it is not pure" and 3.2/3: "Every program shall contain exactly one definition of every non-inline function or object that is used in that program."
Thanks Pete.
Often it is hard to fit all the pieces from the Standard together to be
able to proof something :-)
--
Karl Heinz Buchegger kb******@gascad.at
Karl Heinz Buchegger wrote: Thanks Pete. Often it is hard to fit all the pieces from the Standard together to be able to proof something :-)
Don't be silly. All it takes is fifteen years of study and two or three
week-long standards meetings a year. <g>
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Henley |
last post by:
I first came across rebol a while ago; it seemed interesting but then
i was put off by its proprietary nature, although the core of the
language is a free download.
Recently however, i can't...
|
by: E. Robert Tisdale |
last post by:
What makes a good C/C++ programmer?
Would you be surprised if I told you that
it has almost nothing to do with your knowledge of C or C++?
There isn't much difference in productivity, for...
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode...
|
by: Madhur |
last post by:
Hello
what about this nice way to open a file in single line rather than using
if and else.
#include<stdio.h>
void main()
{
FILE *nd;
clrscr();...
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: Siong.Ong |
last post by:
Dear all,
my PHP aims to update a MySQL database by selecting record
one by one and modify then save.
Here are my PHP, but I found that it doesnt work as it supposed to be,
for example, when...
|
by: Tubular Technician |
last post by:
Hello, World!
Reading this group for some time I came to the conclusion that
people here are split into several fractions regarding size_t,
including, but not limited to,
* size_t is the...
|
by: Daniel.C |
last post by:
Hello.
I just copied this code from my book with no modification :
#include <stdio.h>
/* count characters in input; 1st version */
main()
{
long nc;
nc = 0;
|
by: MU |
last post by:
Hello
I have some code that sets a dropdownlist control with a parameter
from the querystring. However, when the querystring is empty, I get
an error.
Here is my code:
Protected Sub...
|
by: mingke |
last post by:
Hi...
So I have problem with my if condition..I don't know what's wrong but it keeps resulting the wrong answer....
So here's the part of my code I have problem with:
for (i=0; i<size2;...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |