主题:欲穷千里目先去眼中沙
小子不才。今天编程时遇到了难题问题 偶思之不解 遂求解与各位大大
原编码如此:(是对象数组应用的一道例题)我用的是多文件结构写的 偶是一名初学者
望不吝赐教
//head.h
#include <iostream>
using namespace std;
class location
{
public:
location();
location(int xx,int yy);
~location();
void move(int x,int y);
void getx();
void gety();
private:
int X,Y;
};
//location.cpp
#include "head.h"
location::location()
{ X=0;Y=0;cout<<"fault constructor called"<<endl;}
location::location(int xx,int yy)
{ X=xx;Y=yy;cout<<"constructor called"<<endl;}
location::~location()
{cout<<"destructor called"<<endl;}
void location:: move(int x,int y)
{X=x;Y=y;}
void location:: getx()
{cout<<"X:"<<X<<endl;}
void location:: gety()
{cout<<"Y:"<<Y<<endl;}
//main.cpp
#include "head.h"
location::location()
{ X=0;Y=0;cout<<"fault constructor called"<<endl;}
location::location(int xx,int yy)
{ X=xx;Y=yy;cout<<"constructor called"<<endl;}
location::~location()
{cout<<"destructor called"<<endl;}
void location:: move(int x,int y)
{X=x;Y=y;}
void location:: getx()
{cout<<"X:"<<X<<endl;}
void location:: gety()
{cout<<"Y:"<<Y<<endl;}[size=3] [em2]
原编码如此:(是对象数组应用的一道例题)我用的是多文件结构写的 偶是一名初学者
望不吝赐教
//head.h
#include <iostream>
using namespace std;
class location
{
public:
location();
location(int xx,int yy);
~location();
void move(int x,int y);
void getx();
void gety();
private:
int X,Y;
};
//location.cpp
#include "head.h"
location::location()
{ X=0;Y=0;cout<<"fault constructor called"<<endl;}
location::location(int xx,int yy)
{ X=xx;Y=yy;cout<<"constructor called"<<endl;}
location::~location()
{cout<<"destructor called"<<endl;}
void location:: move(int x,int y)
{X=x;Y=y;}
void location:: getx()
{cout<<"X:"<<X<<endl;}
void location:: gety()
{cout<<"Y:"<<Y<<endl;}
//main.cpp
#include "head.h"
location::location()
{ X=0;Y=0;cout<<"fault constructor called"<<endl;}
location::location(int xx,int yy)
{ X=xx;Y=yy;cout<<"constructor called"<<endl;}
location::~location()
{cout<<"destructor called"<<endl;}
void location:: move(int x,int y)
{X=x;Y=y;}
void location:: getx()
{cout<<"X:"<<X<<endl;}
void location:: gety()
{cout<<"Y:"<<Y<<endl;}[size=3] [em2]