:\qimo_1\head.h(12) : fatal error c1189001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp'

有一道C++的问题 请高手帮帮忙 小弟我感激不尽啊_百度知道【转】友元函数,编译出错fatal&error&C1001:&INTERNAL&COMPILER&ERROR&(compiler&file&'msc1.cpp'
原文地址:
同学拿了个很简单的小程序过来问我,重载了个运算符,如果作为成员函数,一点问题没有;如果作为友元函数重载,就会出现下面的编译出错提示:
-------------------Configuration: money - Win32
Debug--------------------
Compiling...
F:\c++workspaces\money\money.cpp(12) : fatal error C1001: INTERNAL
COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)&
Please choose the Technical Support command on the Visual
Help menu, or open the Technical Support help file for more
information
Error executing cl.exe.
money.obj - 1 error(s), 0 warning(s)
最怕这种叽歪的错误,其实程序的编写是没问题的,也会这样。。于是,常规思路,上网搜搜呗。
寻寻觅觅的过程就不罗嗦了,解决的办法如下:
头文件的 #include&iostream& 改成
#include&iostream.h&
然后删除语句
方法二:【0】
不改动头文件那,在类的声明前面加上下面两条语句,作为前导声明
money operator + (const money& account1,const
money& account2)
就都可以编译通过了~
究其原因,我试着说说吧。先说包含头文件的时候,带不带.h的扩展名的意思是差很多的。若用&iostream.h&的话,表示告诉编译器,使用VisualC++6.0的基础开发环境自己的输入输出流类库头文件iostream.h。而&iostream&是指使用ISO
C++标准的输入输出流类库头文件iostream。并非省略扩展名,包含的本身就是两个不同的文件。
如果你觉得没理解,还有下面的这种解释方式:
当使用&iostream.h&时,相当于在c中调用库函数,使用的是全局命名空间,也就是早期的c++实现;当使用&iostream&的时候,该头文件没有定义全局命名空间,必须使用namespace
std;这样才能正确使用cout。【1】
还没明白就算了,知道这么回事先。其实我也不是特别透。
此外,关于fatal error C1001: INTERNAL COMPILER ERROR (compiler file
'msc1.cpp', line 1786) 的错误,还有一说:
因为别的非友元的问题引起的这个错误,具体原因未知,如果遇到,可以用下面的解决方法44看:
一、在Project/Setting/ c/c++中的Project option,从中删除 /Zg 或 /Gz
或者一些个别的比如/oa之类的,然后重写下出错的那行,再编译试试。一次删除一个,如果仍出错那么就说明不是原因,可添加回去再删除别的试试。【2】
二、某大人介绍了自己用到的情况:“我在调用一个自己的函数时出现这个错误,我通过多方努力找到了原因:我的这个函数有一个结构体参数,并且该结构体比较庞大,之前我是将整个结构体都传入而导致编译出错,最后我改成传入该结构体的地址(传引用),这下编译就对了”。【3】
我就简单的贴在这里了。
为了保持严谨的科学态度,下面标明参考文献:
最后,附上那段程序好了
#include&iostream&
#include&cstdlib&
#include&cctype&
int char_to_int(char c);
money operator + (const money& account1,const
money& account2);
class money
&friend money operator + (const
money& account1,const money&
account2);
operator == ( const money& account1);
&money percent(int percent_figure)
&money(long dollars,int cents);
&money(long dollars);
&double get_value()
&void input(istream&
&void output(ostream& outs)
&long all_
int main()
&money luli(1,3),guo(5,8),
&total=luli+
&cout&&"luli's money
&luli.output(cout);
&cout&&"guo's money
&guo.output(cout);
&cout&&"luli's
money+guo's money=";
&total.output(cout);
&if(luli==guo)
&&cout&&"your
money are equal!\n";
&&cout&&"one
of you are richer!\n";
&lugang.input(cin);
&lugang.output(cout);
&lugang.percent(10);
&lugang.output(cout);
&return 0;
money operator + (const money& account1,const
money& account2)
&temp.all_cents=account2.all_cents+account1.all_
bool money:: operator == (const money&
&return(all_cents==account1.all_cents);
money::money(long dollars,int
cents):all_cents(dollars*100+cents)
&if(dollars&0||cents&0)
&&cout&&"illeagal
number for money!\n";
&&exit(1);
money::money(long dollars):all_cents(dollars*100)
&if(dollars&0)
&&cout&&"illeagal
number for money!\n";
&&exit(1);
money::money():all_cents(0)
double money:: get_value() const
&return(all_cents);
void money::input(istream& ins)
&char date1,date2;
&char one_char,decimal_
&cout&&"please enter
one char('-'or'$')\n";
&ins&&one_
&if(one_char=='-')
&&negative=
&&cout&&"please
enter one char('$')\n";
&&ins&&one_
&cout&&"please enter
dollars\n";
&cout&&"enter
decimal_point\n";
&ins&&decimal_
&cout&&"please enter
your cents(date1,date2 in char)\n";
&ins&&date1&&date2;
&if(one_char!='$'||dollars&0||decimal_point!='.'||!isdigit(date1)||!isdigit(date2))
&&cout&&"error
illeagal form for money!\n";
&&exit(1);
&all_cents=dollars*100+char_to_int(date1)*10+char_to_int(date2);
&if(negative)
&&all_cents=-all_
void money::output(ostream& outs) const
&long positive_cents,dollars,
&if(all_cents&0)
&&outs&&"-";
&&positive_cents=labs(all_cents);
&positive_cents=all_
&outs.setf(ios::fixed);
&outs.setf(ios::showpoint);
&outs.precision(2);
&dollars=positive_cents/100;
&cents=positive_cents0;
&outs&&"$"&&
&outs&&".";
&if(cents&10)
&&outs&&"0";
&outs&&cents&&
int char_to_int(char c)
&return(int(c)-int('0'));
money money:: percent(int percent_figure) const
&return all_cents*percent_figure/100;
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。c++ - GCC internal compiler error: Segmentation fault - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I try to include a file, I've defined in cmake.
-DUNINSTD_INC=$ENV{TARGET_FS}/usr/include/unistd.h
I checked this define and UNINSTD_INC is the correct filepath.
The code-snipped, which causes the segmentation fault is the following:
#define SURROUND(x) QUOTE(x)
#define QUOTE(x) #x
#include SURROUND(UNINSTD_INC)
If I compile the code, I get the following error:
unistd.h:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
Does somebody have an idea to fix this problem?
Or an other way to include a predefined file?
gcc version: gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
The fix is easy: Write a bug report, find out who to send it to, and wait for a compiler version that fixes it, as suggested by the error message.
31.2k22850
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledfatal error C1073: 涉及增量编译的内部错误(编译器文件“f:\dd\vctools\compiler\cxxfe\sl\p1\c\main.c”_百度知道error C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) 【c++简单问题】_百度知道

我要回帖

更多关于 fatal error 的文章

 

随机推荐