注册 登录
编程论坛 C++教室

编程中碰到个问题~

wodechuntian 发布于 2017-10-02 12:37, 996 次点击
各位好,代码和错误提示如下,各位高手解答一下,谢谢啦~
只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录
3 回复
#2
yangfrancis2017-10-03 12:44
计算面积不要采用初始化,改成用函数实现应该就可以了
#3
wodechuntian2017-10-04 22:01
回复 2楼 yangfrancis
能帮我看一下这个吗?谢谢。

#include "stdafx.h"
#include <iostream>
using namespace std;
class distance
{
    public:
        float inch;
        float feet;
    distance()
        {
            inch = 0;
            feet = 0;
        }
        distance(float k, float t)
        {
            inch = k;
            feet = t;
        }
        float displaydistance()
        {
            cout << "i= " << inch << endl;
            cout << "f= " << feet << endl;
        }
        distance operator-()
        {
            inch = -inch;
            feet = -feet;
            return distance(inch, feet);
        }    };
int main()
{
    distance d1(11, 10), d2(-5, 11);
    -d1;
    -d2;
    d1.displaydistance();
    d2.displaydistance();
    return 0;
}
每次系统都提示主函数的 'distance': ambiguous symbol。
#4
rjsp2017-10-09 08:41
与 std::distance 冲突,换个名字吧
1