请教一个问题,为什么会"can't execute it"?

yanghaibo_tm 2001-12-28 03:31:02
源代码如下:
#include<iostream.h>

class TEST{
public:
TEST(int i)
{
cout<<"Constructing with"<<i<<".\n";
value=i;
return;
}
~TEST()
{ cout<<"destructing.\n:";
return;
}
int get()
{
return value;
}

private:
int value;
};

void dispiay(Test &obj)
{
cout<<"Display with"<<obj.get()<<".\n";
return;
}

int main()
{
TEST explorer(5);
display(explorer);
return 0;
}
请各位大虾指教!!
...全文
165 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
linning2570 2001-12-28
  • 打赏
  • 举报
回复
((`'-"``""-'`))
        )  -  - (
       /  (o _ o)         \  ( 0 )  /
       _'-.._'='_..-'_
      /`;#'#'#.-.#'#'#;`      \_))  '#'  ((_/
       #. ☆ ☆ ☆  #
       '#. 元旦快乐.#'
       / '#.   .#'        _\ \'#. .#'/ /_
      (((___) '#' (___)))
old_jack 2001-12-28
  • 打赏
  • 举报
回复
应该是你的VC有问题,我试的除一处拼写错误外,正常运行,结果与楼上说的也一样。你自己看看吧,不然重装VC。
yanghaibo_tm 2001-12-28
  • 打赏
  • 举报
回复
!!!
为什么啊,我的vc出问题了吗?
linhui 2001-12-28
  • 打赏
  • 举报
回复

up
yanghaibo_tm 2001-12-28
  • 打赏
  • 举报
回复
to chijiao :
不是啊,我的执行目录与你的编译的目录一样啊。
swordinhand 2001-12-28
  • 打赏
  • 举报
回复
#include<iostream.h>

class TEST{
public:
TEST(int i)
{
cout<<"Constructing with"<<i<<".\n";
value=i;
return;
}
~TEST()
{ cout<<"destructing.\n:";
return;
}
int get()
{
return value;
}

private:
int value;
};

void dispiay(Test &obj) //是void display(TEST &obj)
{
cout<<"Display with"<<obj.get()<<".\n";
return;
}

int main()
{
TEST explorer(5);
display(explorer);
return 0;
}

我就修改了这一处,在vc下是可以编译通过并执行的
执行结果是
Constructing with5.
Display with5.
destructing.
:
yanghaibo_tm 2001-12-28
  • 打赏
  • 举报
回复
to andy:
我去掉了那几个return ,还是一样啊,我用的是vc++ 6.0.
yanghaibo_tm 2001-12-28
  • 打赏
  • 举报
回复
这是书上的一个例子,是来说明构造函数与拷贝构造函数的用法的,原书上用的是display(Test obj),我想是写错了,就加了一个&,可以编译和连接,但是不能execute.
chijiao 2001-12-28
  • 打赏
  • 举报
回复
是执行目录与你的编译的目录不一样,它找不到你所编译的程序.分别在Project->Setting中的Debug与Link中.
andy_lau 2001-12-28
  • 打赏
  • 举报
回复
#include<iostream.h>

class TEST{
public:
TEST(int i)
{
cout<<"Constructing with"<<i<<".\n";
value=i;
return;//构照函数没有返回值,建议去掉

}
~TEST()
{ cout<<"destructing.\n:";
return;//析构函数没有返回值,建议去掉
}
int get()
{
return value;
}

private:
int value;
};

void dispiay(Test &obj)
{
cout<<"Display with"<<obj.get()<<".\n";
return;//既然已经声明函数为空类型了,就不必用return
}

int main()
{
TEST explorer(5);
display(explorer);
return 0;
}
//程序好象没有毛病,但是一下把那几个return 去掉适宜下吧!!

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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