运算符重载
qq_44699909
这个作者很懒,什么都没留下…
展开
-
运算符重载.cpp[运算符重载][C++,类]
//#define _CRTDEG_MAP_ALLOC //检测动态内存泄漏#include #include <stdlib.h>//检测动态内存泄漏#include “Cow.h”#include “Goat.h”#include “pork.h”/*//检测动态内存泄漏#include <crtdbg.h>//替代new#ifdef _DEBUG...原创 2020-02-08 11:01:54 · 364 阅读 · 0 评论 -
Goat.cpp[运算符重载][C++,类]
#include “Goat.h”Goat::Goat(int weight){this->weight = weight;}int Goat::getweight()const{return weight;}bool Goat::operator>(Goat& goat){if (weight > goat.weight) { return tru...原创 2020-02-08 11:00:18 · 223 阅读 · 0 评论 -
Goat.h[运算符重载][C++,类]
#pragma onceclass Goat //羊类{public:Goat(int weight = 0);int getweight()const;//关系运算符重载bool operator>(Goat& goat);bool operator<(Goat& goat);bool operator==(Goat& goat);pri...原创 2020-02-08 10:59:29 · 268 阅读 · 0 评论 -
Cow.cpp[运算符重载][C++,类]
#include “Cow.h”#include “pork.h”#include “Goat.h”Cow::Cow(int weight){this->weight = weight;}pork Cow::operator+(const Goat& goat){/*加法规则:一斤牛肉:两斤猪肉一斤羊肉:三斤猪肉/int tmp = this->wei...原创 2020-02-08 10:58:22 · 241 阅读 · 0 评论 -
Cow.h[运算符重载][C++,类]
#pragma once#include #include using namespace std;class pork;class Goat;class Cow //牛类{public:Cow(int weight = 0);//使用运算符重载来实现变态加法//使用operator运算符重载有一个默认参数是对象本身如自己(Cow)pork operator+(const ...原创 2020-02-08 10:57:07 · 251 阅读 · 0 评论 -
pork.cpp[运算符重载][C++,类]
#include “pork.h”#include int pork::id = 0;pork::pork(int weight){this->weight = weight;}pork::pork(const char* name, int weight, int price){if (!name)name = “空”;this->name = new char[...原创 2020-02-08 10:55:34 · 179 阅读 · 0 评论 -
pork.h[运算符重载][C++,类]
#pragma once#include #include #include using namespace std;#define WEIGHT_KEY “体重”#define PRICE_KEY “单价”#define ID_KEY “编号”#define NAME_KEY “姓名”typedef enum {id_key,weight_key,price_ke...原创 2020-02-08 10:54:34 · 159 阅读 · 0 评论