关于类的问题

weicheichei 2010-11-05 10:21:28
#ifndef STONEWT_H_
#define STONEWT_H_
class Stonewt
{
private:
enum{Lbs_per_stn=14};
int stone;
double pds_left;
double pounds;
public:
Stonewt(double lbs);
Stonewt(int stn,double);
stonewt();
~Stonewt();
void show_lbs()const;
void show_stn()const;
};
#endif
上面是我定义的类,我在后面给构造函数如下:
Stonewt::Stonewt(double lbs)
{
stone=int(lbs)/Lbs_per_stn;
pds_left=int(lbs)%Lbs_per_stn+lbs-int(lbs);
pounds=lbs;
}
Stonewt::Stonewt(int stn,double lbs)
{
stone=stn;
pds_left=lbs;
pounds=stn*Lbs_per_stn+lbs;
}
Stonewt::Stonewt()
{
stone=pounds=pds_left=0.0;
}
~Stonewt()
{
}编译后出现了这样的错误
E:\C++学习\1141\stonewt.cpp(18) : error C2511: 'Stonewt::Stonewt' : overloaded member function 'void (void)' not found in 'Stonewt'
e:\c++学习\1141\stonewt.h(4) : see declaration of 'Stonewt'
E:\C++学习\1141\stonewt.cpp(21) : error C2588: '::~Stonewt' : illegal global destructor
E:\C++学习\1141\stonewt.cpp(23) : warning C4508: 'Stonewt' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
大家帮忙给看看啊,谢谢啦!错误指向红色的部分。
...全文
99 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mumuliang 2010-11-08
  • 打赏
  • 举报
回复
<const_cast>一下taft
mumuliang 2010-11-08
  • 打赏
  • 举报
回复
display 需要传入的是const Stonewt
taft是非const的
weicheichei 2010-11-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 weicheichei 的回复:]
void display(const Stonewt &st,int n)
{
for(int i=0;i<n;i++)
{
cout<<"wow!";
st.show_stn();
}
}
上面我定义的函数,下面是调用的语句,其中taft是定义的一个类,大家帮忙看下啊,谢谢!
Stonewt taft(21.8);
display(taft,2);
[/Quote]
出现的错误是
Compiling...
stone.cpp
Linking...
stone.obj : error LNK2001: unresolved external symbol "void __cdecl display(class Stonewt,int)" (?display@@YAXVStonewt@@H@Z)
Debug/1141.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
中间的其它部分都是对的,因为我在其它模块还用到过,我估计就是调用不对,不知道如何解决。
weicheichei 2010-11-05
  • 打赏
  • 举报
回复
void display(const Stonewt &st,int n)
{
for(int i=0;i<n;i++)
{
cout<<"wow!";
st.show_stn();
}
}
上面我定义的函数,下面是调用的语句,其中taft是定义的一个类,大家帮忙看下啊,谢谢!
Stonewt taft(21.8);
display(taft,2);
ArmStronger 2010-11-05
  • 打赏
  • 举报
回复
class Stonewt
{
private:
enum{Lbs_per_stn=14};
int stone;
double pds_left;
double pounds;
public:
Stonewt(double lbs);
Stonewt(int stn,double);
Stonewt(); //S大写
~Stonewt();
void show_lbs()const;
void show_stn()const;
};

Stonewt::Stonewt(double lbs)
{
stone=int(lbs)/Lbs_per_stn;
pds_left=int(lbs)%Lbs_per_stn+lbs-int(lbs);
pounds=lbs;
}
Stonewt::Stonewt(int stn,double lbs)
{
stone=stn;
pds_left=lbs;
pounds=stn*Lbs_per_stn+lbs;
}

Stonewt::Stonewt()
{
stone=pounds=pds_left=0.0;
}

Stonewt::~Stonewt()//
{
}
無_1024 2010-11-05
  • 打赏
  • 举报
回复
~Stonewt()
{
没有踢得说明 应该是
Stonewt::~Stonewt()
{}
無_1024 2010-11-05
  • 打赏
  • 举报
回复
class Stonewt
{
private:
enum{Lbs_per_stn=14};
int stone;
double pds_left;
double pounds;
public:
Stonewt(double lbs);
Stonewt(int stn,double);
stonewt();//是大写的 不是小写的
~Stonewt();
void show_lbs()const;
void show_stn()const;
};
無_1024 2010-11-05
  • 打赏
  • 举报
回复
stonewt();
应该是大写S不是小写

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧