fatal error C1001: INTERNAL COMPILER ERROR

本文提供了一个C++源代码示例,展示了如何通过友元函数实现运算符重载,包括递增运算符和取负运算符,并讨论了在不同编译器下可能遇到的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源代码

#include<iostream>
using namespace std;
class sample
{
friend void operator ++(sample s1);//定义重载函数为友元函数
friend int operator -(sample s2);//定义重载函数为友元函数
        int n;
public:
        sample(int i) {n=i;}
        //int operator -() {n=-n; return n;}
        //2void operator ++() {n++; }//前缀运算
        //void operator ++(int) {n++; }//后缀运算
        void operator ++(int) {n+=1; }
        void display()
        {
                cout << "n="<<n<<endl;
        }

};
int operator -(sample s2) {s2.n=-s2.n; s2.display();}//类外面定义一个运算符重载
void operator ++(sample s1) {s1.n++; s1.display();}//类外面定义一个运算符重载

main ()
{
        sample b(6),a(6),c(6);
        ++b;
        a++;
        -c;
        a.display();
        b.display();
        c.display();
}

问题

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.

解决:换个编译器,vc6.0的问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值