choco1024 发表于 2008-8-31 16:04

转换构造函数问题

#include "iostream"
using namespace std;
class Complex{
public:
        Complex(){real=0;imag=0;}
        Complex(double r){real=r;imag=0;}
        Complex(double r,double i){real=r;imag=i;}
        friend Complex operator +(Complex c1,Complex c2);
        void display();
private:
        double real;
        double imag;
};
Complex operator +(Complex c1,Complex c2)
{
        Complex c3;
        c3.real=c1.real+c2.real;
        c3.imag=c1.imag+c2.imag;
        return c3;
}
void Complex::display()
{cout<<"("real<<","<<imag"<<i)"<<endl;}
void main()
{
        Complex c1(2.5,3.6),c2(2.0,3.8),c3;
        c3=c1+1.5;
        c3.display();
}

f:\c程序\转换构造函数\late.cpp(8) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1786)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

late.obj - 1 error(s), 0 warning(s)


我没见过那样的错误,那程序代码还是从书上找的,运行结果怎么会那样?!求解,求解。

沿途有鬼 发表于 2008-9-5 19:36

头文件应该这样#include <iostream>

拉普兰德 发表于 2008-10-5 12:19

楼上的不对啊,还是不行

blueboy82006 发表于 2008-10-5 12:22

[quote][bo][un]沿途有鬼[/un] 在 2008-9-5 19:36 的发言:[/bo]

头文件应该这样#include <iostream> [/quote]
兄弟,这有关系吗?不同的用法罢了...

sunkaidong 发表于 2008-10-5 12:34

vc6.0对友元支持不好,换编译器

很远的那颗星 发表于 2008-10-5 12:41

[quote][bo][un]sunkaidong[/un] 在 2008-10-5 12:34 的发言:[/bo]

vc6.0对友元支持不好,换编译器 [/quote]

dong哥,好久不见[em04]

to LZ:
打补丁(SP6)或自已定义名空间 或 换编译..

推荐:换编译,用GCC...

sunkaidong 发表于 2008-10-5 12:46

// s2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "iostream"
using namespace std;
namespace Demo{
class Complex{
public:
    Complex(){real=0;imag=0;}
    Complex(double r){real=r;imag=0;}
    Complex(double r,double i){real=r;imag=i;}
    friend Complex operator +(Complex c1,Complex c2);
    void display();
private:
    double real;
    double imag;
};
Complex operator +(Complex c1,Complex c2)
{
    Complex c3;
    c3.real=c1.real+c2.real;
    c3.imag=c1.imag+c2.imag;
    return c3;
}
void Complex::display()
{
        cout<<"("<<real<<","<<imag<<"<<i)"<<endl;
}
}
void main()
{
        Demo::Complex c1(2.5,3.6),c2(2.0,3.8),c3;
    c3=c1+1.5;
    c3.display();
}

中学?

mason 发表于 2008-10-5 14:10

你的输出语句是不是有问题?

{cout<<"("real<<","<<imag"<<i)"<<endl;}是不是应该改成cout<<"("<<real<<","<<imag<<"<<i)"<<endl;
再加上楼上的名称空间,就通过了

中学者 发表于 2008-10-5 14:32

回复 7# sunkaidong 的帖子

我在这里....那位不是我~![em09]

页: [1]

编程论坛