标题:求助:error C2550: 'Ponit' : constructor initializer lists are only al ...
只看楼主
落叶风
Rank: 2
等 级:论坛游民
帖 子:22
专家分:53
注 册:2011-6-22
结帖率:100%
已结贴  问题点数:10 回复次数:4 
求助:error C2550: 'Ponit' : constructor initializer lists are only allowed on cons
程序代码:
//类定义
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;
}
搜索更多相关主题的帖子: only count 
2012-03-15 09:53
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:10 
Point
Ponit

2012-03-15 11:06
落叶风
Rank: 2
等 级:论坛游民
帖 子:22
专家分:53
注 册:2011-6-22
得分:0 
我找了半天没看见。。。谢谢
2012-03-15 12:10
骆彬彬
Rank: 2
等 级:论坛游民
帖 子:10
专家分:43
注 册:2012-3-13
得分:0 

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


//主函数
#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;

2012-03-15 13:08
BianChengNan
Rank: 8Rank: 8
等 级:贵宾
威 望:13
帖 子:302
专家分:972
注 册:2011-11-30
得分:0 
注意及时结贴楼主。

我的群:149544757 C/C++/Assembly 喜欢交流的朋友进,进群请写消息
2012-03-17 12:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-363224-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019582 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved