Time of Update: 2018-12-06
代碼:#include <iostream>using namespace std;#define PI 3.14159class Shape{public:virtual void Print()=0;virtual float Area()=0;}; class Circle: public Shape{float R;public: Circle(float R);void Print();float Area();};Circle::Circle(float
Time of Update: 2018-12-06
對於比較大的對象,如果將副本傳進函數中,複製,調用建構函式,解構函式,筆記麻煩效率低,所以我們可以把這個對象的引用傳進去.例如void carCopy(Car &destinationCar,const Car &sourceCar){ ...........}這樣子sourceCar就可以保護,不會被修改了.對於一些基本類型,例如int double之類就不必了,完全沒有必要將void Func(int x) 改寫為void Func(const int &x),
Time of Update: 2018-12-06
昨天我編寫了一個程式,很奇怪,以前從來沒有出現過的#include <iostream>using namespace std;int main(){int a=9;int *p; p=&a; cout<<"a 的地址 "<<p<<endl; delete p; }編譯沒有問題,一旦調試的時候就出問題了user breakpoint called from code at
Time of Update: 2018-12-06
任何包含一個或者多個的純虛函數都叫做抽象類別,因此不能對它執行個體化.否則會導致編譯錯誤;從抽象類別繼承而來的類若不覆蓋純虛函數,依然是純虛函數,所以衍生類別務必覆蓋純虛函數純虛函數定義可以到我這一篇原始碼#include <iostream>using namespace std;#define PI 3.1415926class Shape{public:virtual void Print()=0;virtual float Area()=0;}; class Circle:
Time of Update: 2018-12-06
int main()和void main()編譯運行都正常啊,那麼我們該用哪一個呢?其實這兩個在大多數編譯器兩個都可以,那麼我們該用哪一個呢?兩個都隨便用?應該用int main(){return 0;}因為這個符合ANSI的標準,這個在以後的發展中還是可以使用的,return
Time of Update: 2018-12-06
#include <iostream>using namespace std;int main(){int Int1 = 1;int Int2 = 0;const int* pInt1 = &Int1;int* const pInt2 = &Int2; cout<<"*pInt1 = "<<*pInt1<<endl; cout<<"*pInt2 = "<<*pInt2<<endl;
Time of Update: 2018-12-06
//Shape.h,放入標頭檔檔案夾#include <iostream>using namespace std;#define PI 3.1415926class Shape{public:virtual void Print()=0;virtual float Area()=0;}; class Circle: public Shape{float R;public:Circle(float R);void Print();float Area();};class
Time of Update: 2018-12-06
#include <iostream>using namespace std;template <typename Type>Type max(Type x,Type y){if(x>y) {return x; }else {return y; }}template <typename parameter1=int ,typename parameter2=int>class A{ parameter1 x;
Time of Update: 2018-12-06
例如class Car{private:int price;char *brand;public: Car(); Car(int price,char *brand); Car(const Car *car); ~Car();void introduce();}; Car::Car(){}Car::Car(int price,char *brand){this->price = price;this->brand = new
Time of Update: 2018-12-06
#include <iostream>using namespace std;template <typename T>void display(const T& element){ cout<<element<<endl;};//這裡有分號,編譯運行都沒有報錯template <typename S>void show(const S& element){
Time of Update: 2018-12-06
如果類中的任何一個函數時虛函數,應該將解構函式變成虛解構函式;原因是如果解構函式不是虛的話,那麼如下例子#include <iostream>using namespace std;class Mammal{public: Mammal():itsAge(1) { } ~Mammal() {cout<<"解構函式"; } virtual void Speak() const { cout << "Mammal speak!\n";
Time of Update: 2018-12-06
// LISTING 12.10 - Deriving Abstract Classes from Other Abstract Classes#include <iostream>using namespace std;enum COLOR { Red, Green, Blue, Yellow, White, Black, Brown } ;class Animal // common base to both Mammal and Fish{public:
Time of Update: 2018-12-06
#include <iostream>using namespace std;class Complex{private:int x;int y;public: Complex(); Complex(int x,int y); Complex(const Complex& complex); ~Complex();void display() const;};Complex::Complex(){ cout<<"Complex()"&
Time of Update: 2018-12-06
class Base{private:int value;public: Base() { cout<<"Base()"<<endl; } Base(int value) { cout<<"Base(int x)"<<endl;this->value=value; }virtual void display() {
Time of Update: 2018-12-06
首先介紹兩個函數:讀取 ini
Time of Update: 2018-12-06
自己嘗試寫一個這個vector的容器嘛,本來以為很簡單,誰知道寫的時候才發現很多困難,自己也犯看一些白癡且致命的錯誤.例如第一個就是int* source = new int[10];int
Time of Update: 2018-12-06
自己寫了一個玩玩#include <iostream>using namespace std;class vector{private:int* Array;int sizeOfArray;int capacityOfArray;void transfer(int* destination,const int* sourceFirst,const int* sourceLast);public: vector(int capacity=0);
Time of Update: 2018-12-06
通常我們比較flag是否為1,一般如下if(flag==1),有時候因為一些錯誤以致打錯if(flag=1),這樣子編譯器是不是識別的,而且很難人工發現,特別在幾百行代碼中的時候,更難發現.如果比較改成if(1==flag)的話,這樣子如果寫成if(1=flag)編譯器就會報錯這樣子更容易檢查出來,像if(flag=1)沒有語法錯誤的,它有語義錯誤,如果我們不小心把if(1==flag)寫成if(1=flag),就會產生語法錯誤,這樣子就可把語義錯誤轉化為語法錯誤,可以讓編譯器檢錯了,大大提高了
Time of Update: 2018-12-06
什麼時候我們需要用到SetTimer函數呢?當你需要每個一段時間執行一件事的的時候就需要使用SetTimer函數了。 使用定時器的方法比較簡單,通常告訴WINDOWS一個時間間隔,然後WINDOWS以此時間間隔周期性觸發程式。通常有兩種方法來實現:發送WM_TIMER訊息和調用應用程式定義的回呼函數。 1.1 用WM_TIMER來設定定時器先請看SetTimer這個API函數的原型 UINT_PTR SetTimer( HWND hWnd, // 視窗控制代碼
Time of Update: 2018-12-06
1.我們先看看next_permutation這個泛型演算法#include <iostream>#include <algorithm>using namespace std;int main () {int a[] = {1,2,3};do { cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl; }while(next_permutation(