以Circle做例子:
#include"pch.h"
#include<iostream>
#include<string>
#include<opencv2/opencv.hpp>
#include<vector>
#include<algorithm>
#include"Point.h" **//在main函数中要包含所定义类的声明文件,即.h文件**
using namespace std;
using namespace cv;
void test01()
{
Circle c;
c.setX(10);
c.setY(20);
c.getX();
c.getY();
cout << "m_X = " << c.getX() << endl;
cout << "m_Y = " << c.getY() << endl;
}
int main()
{
test01();
system("pause");
}
#include"pch.h"
#include"Point.h" //在类的.cpp文件中也要包含类的声明文件,即.h文件
#include<iostream>
using namespace std;
void Circle::setX(int x) //定义类的构造函数时要添加所定义的类及类作用域符号
{
m_X = x;
}
int Circle::getX()
{
return m_X;
}
void Circle::setY(int y)
{
m_Y = y;
}
int Circle::getY()
{
return m_Y ;
}
#pragma once //避免类的重复定义
class Circle //类的声明
{
public:
void setX(int x); //将类的所有声明都写入.h文件中
int getX();
void setY(int y);
int getY();
private:
int m_Y;
int m_X;
};
因篇幅问题不能全部显示,请点此查看更多更全内容