回 帖 发 新 帖 刷新版面

主题:在VC中好使,为什么在BCB6.0编译不过呢

#include<iostream.h>
class Point
{
     private:
        int X,Y;
        static int countP;
     public:
        Point(int xx=0,int yy=0)
        {
           X=xx; Y=yy; countP++;
        }
     Point(Point &p);                    //这里会出错  
     int GetX()  {return X;}
     int GetY()  {return Y;}
     static void GetC() {cout<<"Object id= "<<countP<<endl;}
};

Point::Point(Point &p)
{
   X=p.X;
   Y=p.Y;
   countP++;
}


int Point::countP=0;              
int main(int argc, char* argv[])
{
        Point A(4,5);
        cout<<"Point A,"<<A.GetX()<<","<<A.GetY();
        A.GetC();
        Point B(A);
        cout<<"Point B,"<<B.GetX()<<","<<B.GetY();
        Point::GetC();
               
        return 0;
}

回复列表 (共7个回复)

沙发

我在CB中编译这段确实没错误。。。
请贴出出错信息

板凳

[C++ Error] Unit1.cpp(22): E2015 Ambiguity between 'Point' and '_fastcall Classes::Point(int,int)'
[C++ Error] Unit1.cpp(28): E2015 Ambiguity between 'Point' and '_fastcall Classes::Point(int,int)'
[C++ Error] Unit1.cpp(39): E2015 Ambiguity between 'Point' and '_fastcall Classes::Point(int,int)'
[C++ Error] Unit1.cpp(42): E2015 Ambiguity between 'Point' and '_fastcall Classes::Point(int,int)'

3 楼

哦 知道了。
跟Classes里面的方法同名了。
你只需#include <iostream.h>
其他的#include 全部去掉 就可以了

4 楼

天!我中午不知怎么就把Point都改成了P,结果编译通过了,这不正想告诉你呢,又看到了你的帖子,太谢谢了!不过按你说的我试了还是有问题,
[Linker Error] Unresolved external '__InitVCL' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '__ExitVCL' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
那为什么你那儿不会出问题呢,是不是我的系统装的不全啊,要不以后我就不用Point这个词了,哈!我是初学者,谢谢你的关照!

5 楼

Point是构造位于Classes.hpp里面的,一个用于构造TPoint的函数。
同名所以冲突。

6 楼

google:

Q: When I try to compile and run the program using Borland C++ Builder v. 5, I get two error messages that refer to linker errors, unresolved external '__InitVCL' and '__ExitVCL'. What is wrong? 

A: What has happened is that when you created the project, the 'C++' and 'Use VCL' options were selected in the Console Wizard dialog box. See step 2(b) in the instructions above. Next time, select only the 'C' and 'Console Application' options. To fix the problem this time without having to create a new project, just add the line '#include <vcl.h> at the top of your program and it will work. 

你在你的头文件中加入#include <vcl.h>应该可以解决问题。

7 楼

#include <vcl.h>是BCB里有的,VC6里认吗?
&P与*p的区别不知楼主有认识过.

我来回复

您尚未登录,请登录后再回复。点此登录或注册