C++
a987860319
这个作者很懒,什么都没留下…
展开
-
全局函数做友元函数
class Building { //让全局的好基友函数变为友元函数; friend void goodGay(Building * building); public: Building() { this->m_sittingRoom = "客厅"; this->m_bedRoom = "卧室"; } public: string m_sittingRoom; private: string m_bedRoom; }; //全局函数; void goodGay.原创 2022-03-01 19:33:48 · 243 阅读 · 0 评论 -
类模板函数的类外实现
#include <iostream> #include <string> #include <vector> #include <fstream> using namespace std; template <typename T1, typename T2> class Person { public: Person(T1 name, T2 age); void showPerson(); T1 m_Name; T2 m_Age; .原创 2022-02-28 11:09:45 · 221 阅读 · 0 评论 -
虚析构和纯虚析构
为了解决在多态情况下,delete父类指针不会调用子类析构函数,导致子类堆区数据释放不了的问题。 #include <iostream> #include <string> using namespace std; class Animal { public: Animal() { cout << "Animal中调用构造函数" << endl; } virtual void speak() = 0;原创 2022-02-17 11:33:41 · 385 阅读 · 0 评论 -
c++纯虚函数例子
#include <iostream> #include <string> #include <vector> #include <fstream> using namespace std; class AbstractBase { public: virtual void Boil() = 0; virtual void Brew() = 0; virtual void PourInCup() = 0; virtual void PutSome..原创 2022-02-17 10:38:12 · 502 阅读 · 0 评论 -
c++ float精度丢失
代码#include <iostream>int main(int argc, const char * argv[]) { using namespace std; float a = 2.34E+22f; float b = a + 1.0f; cout << "a = " << a << endl; cout << "b - a = " << b - a原创 2015-12-12 00:11:03 · 2837 阅读 · 1 评论