无法从 int 函数返回结果
Can't return result from int function
我正在用c++编写一个类继承程序。它的功能是确定三角形何时为直角并计算其面积。
程序如下:
#include <iostream>
using namespace std;
class Puncte
{
public:
int x1,y1;
int x2,y2;
int x3,y3;
Puncte(int a, int b, int c, int d, int e, int f):x1(a),y1(b),x2(c),y2(d),x3(e),y3(f){}
void AfisareP()
{
cout<<x1<<y1<<x2<<y2<<x3<<y3<<endl;
}
};
class Latura
{
protected:
int l1, l2, l3;
public:
void LatimeaL(int a, int b, int c)
{
l1 = a;
l2 = b;
l3 = c;
}
};
class Triunghi: public Latura
{
public:
int AriaTrDr()
{
return l1*l3/2;
}
};
int main()
{
Puncte p(2,2,2,2,2,2);
Latura l;
l.LatimeaL(1,2,4);
Triunghi t;
if (p.x1 == p.x3 && p.y1 == p.y2)
{
cout << "Triunghi dreptunghic!" << endl;
cout << t.AriaTrDr() << endl;
}
return (0);
}
一切都很好,但它没有显示正确的结果,但地址,我不知道如何修复它。
结果如下。
Triunghi dreptunghic!
513242112
您正在对对象l
调用l.LatimeaL(1,2,4);
。
对象t
与Triunghi t;
一起创建。它不是通过调用Latimeal
函数来初始化的。因此,您将得到一个未定义的值。
您需要调用t.Latimeal(1,2,4)
函数来初始化它,在创建对象之后。
相关文章:
- C++Brute Force攻击函数不会返回结果
- 如何在一个表达式中生成并返回结果?
- 使用std::tie进行类似golang的错误处理,同时返回结果,是否有缺点?(C++11)
- C++ 线程端回调并返回结果
- C++使用存储过程返回结果
- reinterpret_cast总是返回结果C++?
- 尝试以随机字符(长读取)打印字符串返回结果
- 通过C 中的参考返回结果
- 使用枚举确定返回结果的类型(使用宏的黑客)
- 返回结果不可见
- 打开一个 Shell 程序,向其传递参数,然后返回结果
- 如何在递归函数中计算返回结果
- 整数列表的交集-无法返回结果列表
- 来自 open() 的返回结果代码之间的差异:25 与 3
- 使用 c++11 线程返回结果的正确方法是什么
- 传递StringBuilder并从c++dll向c#返回结果
- 如何跳出一些深度递归的函数并直接返回结果
- 使用MPI临时接收数据,然后返回结果
- C++,我不知道为什么我的函数不返回结果
- QDialog show()后面跟着返回结果操作