本人刚学C++,希望大家多多帮助
程序代码如下:
#include <iostream>

using namespace std;

class money
{
public:
    money();
    money(int i_yuan,int i_jiao,int i_fen);
    int getmoney();
    friend int access(money money2);
    friend int operator +(money money1,money money2);
private:
    int yuan;
    int jiao;
    int fen;
};

money::money()
{
    yuan=0;
    jiao=0;
    fen=0;
}
money::money(int i_yuan,int i_jiao,int i_fen)
{
    yuan=i_yuan;
    jiao=i_jiao;
    fen=i_fen;
}
int money::getmoney()
{
    return yuan*100+jiao*10+fen;
}

int access(money money2)
{
    return money2.yuan*100+money2.jiao*10+money2.fen;
}
int operator +(money money1,money money2)
{
    return money1.yuan*100+money1.jiao*10+money1.fen+money2.yuan*100+money2.jiao*10+money2.fen;
   
}

int main()
{
    money money1(1,2,40),money2(1,2,30);
    cout<<money2.getmoney()<<endl;
    cout<<access(money1)<<endl;
    cout<<(money1+money2)<<endl;
    getchar();
    return 1;
}
Dev-C++可以成功编译并执行!
但是VC编译出错:
--------------------Configuration: monydemo - Win32 Debug--------------------
Compiling...
monydemo.cpp
D:\wzz\monydemo.cpp(12) : 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.

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