注册 登录
编程论坛 C++教室

求助:error C2550: 'Ponit' : constructor initializer lists are only allowed on cons

落叶风 发布于 2012-03-15 09:53, 1707 次点击
程序代码:
//类定义
class Point
{
public:
    Point(int x=0,int y=0):x(x),y(y) {}
    Ponit(const Point &p);
    ~Point() {count--;}
    int getx()  const {return x;}
    int gety()  const {return y;}
    static void showcount();
private:
    int x,y;
    static int count;
};

//类实现
#include"Point.h"
#include<iostream>
using namespace std;

int Point::count=0;
Point::Ponit(const Point &p):x(p.x),y(p.y)
{
    count++;
}

void Point::showcount()
{
    cout<<"Objiect count="<<count<<endl;
}

//主函数
#include"Point.h"
#include<iostream>
using namespace std;


int main()
{
    Point a(4,5);
    cout<<"Point A:"<<a.getx()<<","<<a.gety();
    Point::showcount();

    Point b(a);
    cout<<"Point B:"<<b.getx()<<","<<b.gety();
    Point::showcount();

    return 0;
}
4 回复
#2
rjsp2012-03-15 11:06
Point
Ponit

#3
落叶风2012-03-15 12:10
我找了半天没看见。。。谢谢
#4
骆彬彬2012-03-15 13:08

我改了一下,不知道是不是你想要的结果。。。
改了你写有问题的东东,
希望能帮到你


//主函数
#include<iostream>
using namespace std;
#include"Point.h"
int main()
{
    Point a(4,5);
    cout<<"Point A:"<<a.getx()<<","<<a.gety();
    a.showcount();
    Point b(a);
    cout<<"Point B:"<<b.getx()<<","<<b.gety();
    b.showcount();
    return 0;
}
上面是主函数,然后新建一个.h文件去写类point
//类定义+类实现
class Point
{
public:
    Point(int x=0,int y=0) {x=x;y=y;}
    //Ponit(const Point &p);
    ~Point() {count--;}
    int getx()  const {return x;}
    int gety()  const {return y;}
    //void showcount();
    Ponit(const Point &p){x=p.x;y=p.y;count++;}
    void showcount()
{
    cout<<"Objiect count="<<count<<endl;
}
private:
    int x,y;
    static int count;
   


};
int Point::count=0;

#5
BianChengNan2012-03-17 12:30
注意及时结贴楼主。
1