在VC++6.0下C++嵌入源文件,欲将point.h嵌入,具体如何操作?
//point.h#include<iostream>usingnamespacestd;classPoint{public:Point(intxx=0,intyy=0)...
//point.h
#include<iostream>
using namespace std;
class Point{
public:Point(int xx=0,int yy=0) {X=xx;Y=yy;count++;}
Point(Point &p);
~Point(){count--;}
int getx(){return X;}
int gety(){return Y;}
static void getc(){cout<<"Object id="<<count<<endl;}
private:int X,Y;
static int count;
};
//point.cpp
#include<point.h>
int Point::count=0;
Point::Point(Point &p){
X=p.X;Y=p.Y;count++;}
//5_10.cpp
#include"point.h"
void main(){
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();
} 展开
#include<iostream>
using namespace std;
class Point{
public:Point(int xx=0,int yy=0) {X=xx;Y=yy;count++;}
Point(Point &p);
~Point(){count--;}
int getx(){return X;}
int gety(){return Y;}
static void getc(){cout<<"Object id="<<count<<endl;}
private:int X,Y;
static int count;
};
//point.cpp
#include<point.h>
int Point::count=0;
Point::Point(Point &p){
X=p.X;Y=p.Y;count++;}
//5_10.cpp
#include"point.h"
void main(){
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();
} 展开
3个回答
展开全部
#include <iostream.h>
// using namespace std; // MS VC++ comment out the line
#include "point.h"
#include "point.cpp"
void main(){
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();
}
--------------------------------------------
// point.cpp
int Point::count=0;
Point::Point(Point &p){
X=p.X;Y=p.Y;count++;}
----------------------------------
// point.h
class Point{
public:Point(int xx=0,int yy=0) {X=xx;Y=yy;count++;}
Point(Point &p);
~Point(){count--;}
int getx(){return X;}
int gety(){return Y;}
static void getc(){cout<<"Object id="<<count<<endl;}
private:int X,Y;
static int count;
};
---------------------------
MS VC++ 编译通过。
// using namespace std; // MS VC++ comment out the line
#include "point.h"
#include "point.cpp"
void main(){
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();
}
--------------------------------------------
// point.cpp
int Point::count=0;
Point::Point(Point &p){
X=p.X;Y=p.Y;count++;}
----------------------------------
// point.h
class Point{
public:Point(int xx=0,int yy=0) {X=xx;Y=yy;count++;}
Point(Point &p);
~Point(){count--;}
int getx(){return X;}
int gety(){return Y;}
static void getc(){cout<<"Object id="<<count<<endl;}
private:int X,Y;
static int count;
};
---------------------------
MS VC++ 编译通过。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
据说是把point.h,point.cpp(里面需要#include "point.h")和5_10.cpp放在一个工程里一起编译就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
extern 作外部声明
或者可以预编译的时候包含进来
#include "point.h"
或者可以预编译的时候包含进来
#include "point.h"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询