• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            程序讓生活更美好

            半畝方塘 天光云影

              C++博客 ::  :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
              55 隨筆 :: 4 文章 :: 202 評(píng)論 :: 0 Trackbacks

            Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題

               有兩段程序,其實(shí)應(yīng)該是一段程序,只是稍微有點(diǎn)不同。程序

            的主要目的很簡單,就是要輸出1-25的平方根和平方。


               第一段在Dev-C++中編譯通過的,就叫程序一:

             1#include <iostream>
             2#include <math.h>
             3using namespace std;
             4int main(){
             5    cout<<"N    平方根    平方"<<endl;
             6    for(int i=1;i<=25;i++){
             7        cout<<i<<"\t"<<sqrt(i)<<"\t"<<pow(i,2)<<endl;
             8        }

             9        getchar();
            10        return 0;
            11}

            12

               第二段在VC2005中編譯通過的,就叫程序二:
             1#include <iostream>
             2#include <math.h>
             3using namespace std;
             4int main(){
             5    cout<<"N    平方根        平方"<<endl;
             6    for(int i=1;i<=25;i++){
             7        cout<<i<<"\t"<<sqrt((double)i)<<"\t\t"<<pow((double)i,2)<<endl;
             8        }

             9        getchar();
            10        return 0;
            11}

            12
               兩段程序的主要區(qū)別就是sqrt和pow函數(shù)中的參數(shù)類型。

             
              現(xiàn)象:
                     程序一在Dev-C++中可以輕易編譯通過,程序二在Dev-C++中也可以輕易編譯通過。
                      程序一在VC2005中無法編譯通過,程序二是可以的,程序一在VC2005中編譯的時(shí)候會(huì)提示以下錯(cuò)誤。
               錯(cuò)誤如下:
                   Error 1 error C2668: 'sqrt' : ambiguous call to overloaded function e:\C\vc2005\2\p7\p7\3.cpp 7
                  Error 2 error C2668: 'pow' : ambiguous call to overloaded function e:\C\vc2005\2\p7\p7\3.cpp 7

               
            在Dev-C++中的math.h中,這兩個(gè)數(shù)學(xué)函數(shù)的原型是
            _CRTIMP double __cdecl pow (double, double);
            _CRTIMP double __cdecl sqrt (double);
             
                在VC2005中的math.h中,這兩個(gè)數(shù)學(xué)函數(shù)的原型是
                    double  __cdecl pow(__in double _X, __in double _Y);
                    double  __cdecl sqrt ((__in double _X);

             其中多出來的__in的介紹如下:
             If you examine the library header files, you will notice some unusual annotations such as __in_z and __out_ecount_part. These are examples of Microsoft's standard source code annotation language (SAL), which provides a set of annotations to describe how a function uses its parameters—the assumptions it makes about them, and the guarantees it makes upon finishing. The header file <sal.h> defines the annotations.
            具體的可以看
            http://msdn2.microsoft.com/en-us/library/ms235402.aspx


                  函數(shù)的原型都是差不多的,參數(shù)類型也是一樣。int類型賦值給double應(yīng)該是沒有問題的,會(huì)進(jìn)行隱式轉(zhuǎn)換,不知道VC2005怎么不行?一直都聽說Dev-C++對(duì)C++的標(biāo)準(zhǔn)支持的很不錯(cuò),微軟的最新的C++開發(fā)工具在支持C++標(biāo)準(zhǔn)方面也取得了突飛猛進(jìn)的進(jìn)步,現(xiàn)在一個(gè)程序,在不同地方卻不能同時(shí)編譯通過,我不知道是不是哪個(gè)對(duì)標(biāo)準(zhǔn)的支持有什么問題,還是編譯器提供的安全性不同的原因呢?疑惑ing。
                
            posted on 2005-12-30 18:22 北風(fēng)之神007 閱讀(6218) 評(píng)論(6)  編輯 收藏 引用 所屬分類: c/c++Tools

            評(píng)論

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2006-01-05 12:07 夢在天涯
            微軟的2005對(duì)目前c++標(biāo)注好多的都不支持!

            增加了安全機(jī)制!  回復(fù)  更多評(píng)論
              

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2006-01-08 00:19 斑竹
            我看VC++ 2005非常優(yōu)秀,我痕喜歡
            你把for(int i=1;i<=25;i++){
            定義為float就可以了  回復(fù)  更多評(píng)論
              

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2006-01-20 13:34 鄭磊
            終于找到大俠了,我也下了一個(gè)2005,用起來和6.0差距挺大的,請(qǐng)大哥教我兩招吧,謝謝啦。。。。。。。。。。QQ:504831139 E-MAIL:zhengleifrank200@163.com  回復(fù)  更多評(píng)論
              

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2006-01-24 16:11 noar
            用vc2005的ide就行了,不用其余的功能  回復(fù)  更多評(píng)論
              

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2006-03-28 16:10 ujskilor
            我有個(gè)dev c++的 模板函數(shù)調(diào)用錯(cuò)誤的問題請(qǐng)教!

            template <typename Type>
            inline Type max( Type t1, Type t2 )
            { return t1 > t2 ? t1 : t2; }

            template <typename elemType>
            inline elemType max( const vector<elemType> &vec )
            { return *max_element( vec.begin(), vec.end() ); }

            template <typename arrayType>
            inline arrayType max( const arrayType *parray, int size )
            { return *max_element( parray, parray+size ); }
            上述是我在頭文件中聲明的模板函數(shù)
            在cpp文件中調(diào)用,出現(xiàn)錯(cuò)誤
            note D:\ACpp\moban\mb.h:15 candidates are: Type max(Type, Type) [with Type = int]

            但是在vc 和bcb中良好。。  回復(fù)  更多評(píng)論
              

            # re: Dev-c++和VC2005中編譯同一個(gè)程序出現(xiàn)的問題 2008-09-02 19:49 trim
            重載解析錯(cuò)誤,對(duì)sqrt(int, int)的解析過程中,出現(xiàn)多義性。

            int可能隱式轉(zhuǎn)換為float, double, long double.

            float sqrt(float);
            double sqrt(double);
            long double sqrt(long double);

            vc2005等支持標(biāo)準(zhǔn)c++時(shí),可能要等微軟把C++標(biāo)準(zhǔn)委員會(huì)買了的時(shí)候吧。 哈哈  回復(fù)  更多評(píng)論
              

            亚洲国产精品无码久久久秋霞2| 亚洲午夜久久久久妓女影院 | 久久久久久久久久久精品尤物 | 99久久精品国内| 国产成人精品综合久久久| 亚洲日韩欧美一区久久久久我| 久久无码中文字幕东京热| 青青草原综合久久| 久久久久久久久久久精品尤物| 久久―日本道色综合久久| 久久精品aⅴ无码中文字字幕不卡| 国产精品欧美久久久天天影视| 国产免费久久精品99re丫y| 久久九九全国免费| 久久夜色精品国产噜噜噜亚洲AV| 久久久久国产| 日本免费久久久久久久网站| 久久人人爽人人爽人人片AV麻烦| 久久久久国产精品嫩草影院 | 国产成人综合久久精品尤物| 亚洲va久久久噜噜噜久久天堂| 国产伊人久久| 91精品国产高清久久久久久91 | 久久人人爽人人爽人人片AV东京热| 国产视频久久| 久久精品无码一区二区三区日韩| 亚洲AV无码成人网站久久精品大| 久久亚洲国产成人影院| 日日狠狠久久偷偷色综合0 | 精品久久久久久无码专区 | 欧美久久久久久精选9999| 狠狠色噜噜狠狠狠狠狠色综合久久| 色欲综合久久中文字幕网| 亚洲国产另类久久久精品黑人 | 国产AV影片久久久久久| 国内精品久久久久久久coent| 青青草原综合久久大伊人精品| 亚洲国产精久久久久久久| 中文字幕成人精品久久不卡 | 久久伊人五月丁香狠狠色| 久久久一本精品99久久精品88|