C++類繼承之子類調(diào)用父類的構(gòu)造函數(shù)的實例詳解
C++類繼承之子類調(diào)用父類的構(gòu)造函數(shù)的實例詳解
父類HttpUtil:
#pragma once
#include <windows.h>
#include <string>
using namespace std;
class HttpUtil
{
private:
LPVOID hInternet;
LPVOID hConnect;
LPVOID hRequest;
protected:
wchar_t * mHostName;
short mPort;
string sendRequest(WCHAR * pvHostName, short pvPort, WCHAR * pvUrl, WCHAR * pvMethod, char * pvPostData, int pvPostDataLen);
public:
HttpUtil(wchar_t * pvHostName, short pvPort);
~HttpUtil();
void reset();
};
構(gòu)造函數(shù)有兩個參數(shù),host和port , 子類BmsNetUtil繼承它, 并將host/port封裝在里面, 主程序調(diào)用BmsNetUtil時無需再指定host/port參數(shù) , 這時應(yīng)該這樣寫:
#pragma once
#include <windows.h>
#include <string>
#include "HttpUtil.h"
using namespace std;
class BmsNetUtil :public HttpUtil
{
protected:
public:
BmsNetUtil();
~BmsNetUtil();
bool login();
};
BmsNetUtil 構(gòu)造函數(shù)的實現(xiàn):
BmsNetUtil::BmsNetUtil():HttpUtil(TEXT(C_SITE),C_PORT)
{ .....
}
在構(gòu)造函數(shù)后面加上:父類的構(gòu)造語句就可以了...
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
MFC創(chuàng)建模態(tài)對話框和非模態(tài)對話框的方法
這篇文章主要介紹了MFC創(chuàng)建模態(tài)對話框和非模態(tài)對話框的方法,需要的朋友可以參考下2014-07-07
C語言中操作sqlserver數(shù)據(jù)庫案例教程
這篇文章主要介紹了C語言中操作sqlserver數(shù)據(jù)庫案例教程,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
2~62位任意進(jìn)制轉(zhuǎn)換方法(c++)
下面小編就為大家?guī)硪黄?~62位任意進(jìn)制轉(zhuǎn)換方法(c++)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06

