avatar
不许歧视胖子# Joke - 肚皮舞运动
f*y
1
#include
using namespace std;
template class complex {
public:
complex(T re, T im) { re = re, im=im ;};
void print(){cout<private:
T re,im;
};
int main()
{
complex(2,3).print();
complex c = complex(3,4);
c.print();
}
avatar
b*h
2
内裤广告,胖子也能代言。
avatar
Z*4
3
-858993460+-858993460i
-858993460+-858993460i
我运行就是这个结果
谁来解释下为什么?
avatar
z*n
4
这俩好像是同一个人

【在 b*****h 的大作中提到】
: 内裤广告,胖子也能代言。
avatar
t*t
5
因为这一句
complex(T re, T im) { re = re, im=im ;};
应该用this->re = re, this->im = im;
不然就是undefined value
avatar
b*a
6
你还真是足球盲啊

【在 z*********n 的大作中提到】
: 这俩好像是同一个人
avatar
f*y
7
complex(T re, T im) { re = re, im=im ;};
成员变量被参数屏蔽了。改成下面的就行了。
complex(T r, T i) { re = r, im=i ;};
avatar
r*y
8
hiding

【在 Z**********4 的大作中提到】
: -858993460+-858993460i
: -858993460+-858993460i
: 我运行就是这个结果
: 谁来解释下为什么?

avatar
c*r
9
template class complex {
public:
complex(T re, T im) { _re = re, _im=im ;};
void print(){cout<<_re>private:
T _re,_im;
};
avatar
f*y
10
#include
using namespace std;
template class complex {
public:
complex(T re, T im) { re = re, im=im ;};
void print(){cout<private:
T re,im;
};
int main()
{
complex(2,3).print();
complex c = complex(3,4);
c.print();
}
avatar
Z*4
11
-858993460+-858993460i
-858993460+-858993460i
我运行就是这个结果
谁来解释下为什么?
avatar
t*t
12
因为这一句
complex(T re, T im) { re = re, im=im ;};
应该用this->re = re, this->im = im;
不然就是undefined value
avatar
f*y
13
complex(T re, T im) { re = re, im=im ;};
成员变量被参数屏蔽了。改成下面的就行了。
complex(T r, T i) { re = r, im=i ;};
avatar
r*y
14
hiding

【在 Z**********4 的大作中提到】
: -858993460+-858993460i
: -858993460+-858993460i
: 我运行就是这个结果
: 谁来解释下为什么?

avatar
c*r
15
template class complex {
public:
complex(T re, T im) { _re = re, _im=im ;};
void print(){cout<<_re>private:
T _re,_im;
};
avatar
l*y
16
这个是改错题么?
avatar
r*1
17
那如果改正后,结果是5和7?
cout<里面的i是干嘛的啊?
avatar
b*k
18
结果应该是
2+3i
3+4i
这是复数。i是虚数单位。
avatar
r*t
19
c++ 陷阱很多啊。其他语言强制写这个就不会有这问题了。

【在 t****t 的大作中提到】
: 因为这一句
: complex(T re, T im) { re = re, im=im ;};
: 应该用this->re = re, this->im = im;
: 不然就是undefined value

avatar
z*y
20
this is valy bad coding
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。