这有什么问题? [英] what is wrong with this?

查看:88
本文介绍了这有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


这个简单程序有问题:


#include< iostream>

#include< fstream>

class Point {

public:

int x,y;

Point(int x = 0,int y = 0)

{this-> x = x;这 - > Y = Y; }

~Point(){}

};

class Curve {

public:

virtual int getValue(const double t)= 0;

virtual~Curve();

};

class LineCurve:公共曲线{

私人:

点数据[2];

双dt;

公开:

int getValue(const double dt){return 0; }

~LineCurve(){}

};


int main(无效)

{

曲线* ptr;


ptr = new LineCurve;

返回0;

}

Wenn我评论ptr = new LineCurve;排除,然后代码编译。

Otherweis我收到链接错误。这有什么不对?它应该是与虚拟机有关的东西,但是我找不到它?


祝你好运。

Erdal Mutlu

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

推荐答案

Erdal MUTLU写道:
Erdal MUTLU wrote:

你好,
<我有这个简单程序的问题:
#include< iostream>
#include< fstream>
class Point {
public:
int x,y;
Point(int x = 0,int y = 0)
{this-> x = x;这 - > Y = Y; }
~Point(){}
};
类曲线{
public:
virtual int getValue(const double t)= 0;
virtual 〜曲线();
};

类LineCurve:公共曲线{
私人:
点数据[2];
双dt;
public:
int getValue(const double dt){return 0; }
~LineCurve(){}
};

int main(无效)
{
曲线* ptr;
ptr = new LineCurve;
返回0;
}

Wenn我评论ptr = new LineCurve;排除,然后代码编译。
其他我得到链接错误。


好​​吧。通常链接器告诉你什么是错的

这里有什么问题?

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?




你没有看到错误信息。

如果我将程序剪切并粘贴到VC ++中,链接器会告诉我:


错误LNK2001:未解析的外部符号" public:virtual __thiscall Curve ::〜曲线(无效)


所以它说:Hay哥们。我找不到Curve析构函数的实现。

查找代码,代码是对的。你声明了一个析构函数但是没有地方

有一个实现它。


Changr to:


class Curve {

public:

virtual int getValue(const double t)= 0;

virtual~Curve(){}

};


^

|

*


-

Karl Heinz Buchegger
kb******@gascad.at


Karl Heinz Buchegger写道:
Karl Heinz Buchegger wrote:


错误LNK2001:未解析的外部符号" public:virtual __thiscall Curve: :〜曲线(无效)

所以它说:干草哥们。我找不到Curve析构函数的实现。
查找代码,代码是对的。你宣布了​​一个析构函数,但无处


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




....链接器是....


-

Karl Heinz Buchegger
kb******@gascad.at


hi!
hi!
错误LNK2001:未解析的外部符号" public:virtual __thiscall
Curve :: ~Curve(void)
所以它说:干草哥们。我找不到Curve的析构函数
的实现。查找代码,代码是正确的。你声明了一个析构函数,但
没有任何实现。
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.




我对此有疑问。什么是

析构函数的实现需要,当它从未被调用时?该对象在

可用内存上分配,但从不以删除方式发布,因此不会调用析构函数!?我想b $ b我认为我得到的东西非常错,但是什么?

谢谢。


问候,

sev



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


这篇关于这有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆