学习C/C++的困惑,高手请进

Jarrylogin 2004-06-14 12:51:36
1。什么叫复制构造函数?怎么用它
2。volatile关键字的作用。怎么用
3。setjmp和longjmp函数是C语言的函数吗?什么意思,怎么用
...全文
509 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hotm12223 2004-06-15
  • 打赏
  • 举报
回复
有疑问可以到这个论坛上来发帖子,斑竹很牛的http://203.93.63.237/cgi-bin/forums.cgi?forum=2
siemun2002 2004-06-15
  • 打赏
  • 举报
回复
#include<iostream.h>
//重载赋值函数 不成功
class point
{
private:
int a;
int b;
public:
point():a(3),b(4){};//无参默认构造函数
point(int m,int n):a(m),b(n){cout << "一般构造";};//一般构造函数
point(const point & p):a(p.a),b(p.b){cout << "拷贝构造";};//拷贝构造函数
point & operator =(const point & temp){a=temp.a;b=temp.b;return *this;cout << "重载赋值";}//重载赋值函数
void put(){cout<<"a="<<a<<" b="<<b<<endl;}
};
int main()
{
point p1;
point p2(10,20);
point p3=p2;
point p4(p2);
p1.put();
p2.put();
p3.put();
p4.put();
cin.get();
return 0;
}
fanbest 2004-06-14
  • 打赏
  • 举报
回复
1,,不就是拷贝构造函数么?

给你代码
class abc
{
abc(abc tt)
{
this->x=tt.x
}
int set(int n)
{
this->x=n;
}
private:
int x;
}

然后可以声明个类
abc a1;
a1.set(7);
abc a2(a1);

这就达到了拷贝构造的目的。


至于剩下两个,我回去查查msdn再说,呵呵,msdn绝对是个好东西,有空多用用他
Wolf0403 2004-06-14
  • 打赏
  • 举报
回复
setjmp/longjmp 是非局部跳转。
setjmp 第一次调用的时候备份栈状态,然后返回 0;
longjmp 调用只好程序执行点回到对应 setjmp 的位置,恢复栈状态,然后 setjmp 返回非 0 值。
示例:

jmp_buf buf;

if (setjmp(buf) == 0)
{
// 第一次经过 setjmp 的时候进行这里的代码。
}
else
{
// 某处调用 longjmp 之后运行到这里。
}
talkingmute 2004-06-14
  • 打赏
  • 举报
回复
#include<iostream.h>
class point
{
private:
int a;
int b;
public:
point():a(3),b(4){};//无参默认构造函数
point(int m,int n):a(m),b(n){};//一般构造函数
point(const point & p):a(p.a),b(p.b){};//拷贝构造函数
point & operator =(const point & temp){a=temp.a;b=temp.b;return *this;}//重载赋值函数
void put(){cout<<"a="<<a<<"b="<<b<<endl;}
};
int main()
{
point p1;
point p2(10,20);
point p3=p2;
point p4(p2);
p1.put();
p2.put();
p3.put();
p4.put();
return 0;
}
xjp6688 2004-06-14
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/17/17606.shtm
qwertasdfg123 2004-06-14
  • 打赏
  • 举报
回复
以上是摘自msdn上的。
qwertasdfg123 2004-06-14
  • 打赏
  • 举报
回复
3。
The setjmp function saves a stack environment, which you can subsequently restore using longjmp. When used together, setjmp and longjmp provide a way to execute a “non-local goto.” They are typically used to pass execution control to error-handling or recovery code in a previously called routine without using the normal calling or return conventions.

A call to setjmp saves the current stack environment in env. A subsequent call to longjmp restores the saved environment and returns control to the point just after the corresponding setjmp call. All variables (except register variables) accessible to the routine receiving control contain the values they had when longjmp was called.

setjmp and longjmp do not support C++ object semantics. In C++ programs, use the C++ exception-handling mechanism.

qiupid 2004-06-14
  • 打赏
  • 举报
回复
1,对于数据成员中有指针的类,一般都应有一个copy constructor.
2,可对比const.
3,好像是16位的产物,已经不大用了。
sevencat 2004-06-14
  • 打赏
  • 举报
回复
3类似于C++的异常处理。
geland 2004-06-14
  • 打赏
  • 举报
回复
拷贝构造函数 的参数必须是const 的引用!!
kaphoon 2004-06-14
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/17/17606.shtm
qwertasdfg123 2004-06-14
  • 打赏
  • 举报
回复
1.为了深拷贝而产生了copy construct。
2.volatile是声明一个变量在它生命周期外可以被改变。
3。查看msdn。
fanbest 2004-06-14
  • 打赏
  • 举报
回复
int set(int n)
{
..........

return 0;
}

应该有返回值的,不好意思,粗心

65,206

社区成员

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

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