1 你终于还是选择了cv侠
你开始觉得不甘,于是你开始去复习c++面向对象的基础
你打开了菜鸟教程,并进入了面向对象系列的学习
https://www.runoob.com/cplusplus/cpp-classes-objects.html
同时,你创建了一个QT的console程序
你开始了解c++里面的对象:
你发现,它和java有一些区别
class Box
{
public:
double length; // 盒子的长度
double breadth; // 盒子的宽度
double height; // 盒子的高度
};
你学着它的样子定义了一个对象
你回想起头文件:定义变量和函数
你会想起源文件:实现函数
于是你创建一对头,源文件
box.h
#ifndef BOX_H
#define BOX_H
class Box
{
public:
Box();
int width;
int height;
int length;
public:
int sum();
};
#endif // BOX_H
box.cpp
#include "box.h"
Box::Box()
{
};
int Box::sum(){
return this->width+this->height+this->length;
}
你做了一个测试:
#include <QCoreApplication>
#include <iostream>
using namespace std;
#include"box.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// printf("hello world");
Box box;
box.height = 22;
box.width = 10;
box.length = 30;
cout<<"sum of box ="<<box.sum();
return a.exec();
}
你开始思考
Box box与java中Box box = new Box();
的区别