之前在研究AirSim代码时,发现其中MavlinkCom模块,都是写一个MavlinkConnection之类的类,然后再写一个MavlinkConnectionImpl进行实现.一般来说我们都是在设计模式中,发现可以利用接口和实现的分离,来降低程序的耦合度,提高代码的普适性.
不过在C++中,这样做也有另一个方面(编译速度,模块分离)方面的考虑.
下面这段代码,是一段要与COM组建交互的SpeechProvider类,定义大概可以是下面那样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
//Header File #pragma once #include <atlbase.h> class SpeechProvider { CComPtr<***> comObj; public: SpeechProvider(); ~SpeechProvider(); int Speak(const char* text); }; //Cpp File #include "SpeechProvider.h" SpeechProvider::SpeechProvider() { //Initialize COM Object } SpeechProvider::~SpeechProvider() { //Uninitialize COM Object } int Speak(const char* text) { //Do Something } |
在SpeechProvider里自然地引入一个相对安全的CComPtr指针,并自然而然地引入atlbase.h到include这个SpeechProvider的所有文件中.
这样将各个地方的头文件全部引入,有时会导致莫名其妙的语法错误(编译器:???是我的锅喽),命名空间混乱,编译速度减慢等等可能的风险.
因为C++在头文件里面只要声明了类型,就能定义那个类型的指针,于是可以以如下的方式,将COM模块头文件限定在SpeechProvider功能的头文件中.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
//Header File #pragma once class SpeechProviderImpl; class SpeechProvider { SpeechProviderImpl* impl; public: SpeechProvider(); ~SpeechProvider(); int Speak(const char* text); }; //Cpp File #include "SpeechProvider.h" #include <atlbase.h> class SpeechProviderImpl { CComPtr<***> comObj; public: SpeechProviderImpl(); ~SpeechProviderImpl(); int Speak(const char* text); }; SpeechProviderImpl::SpeechProviderImpl() { //Initialize COM Object } SpeechProviderImpl::~SpeechProviderImpl() { //Uninitialize COM Object } int SpeechProviderImpl::Speak(const char* text) { //Do Something } SpeechProvider::SpeechProvider() { impl=new SpeechProviderImpl(); } SpeechProvider::~SpeechProvider() { delete impl; } int SpeechProvider::Speak(const char* text) { impl->Speak(text); } |
SpeechProviderImpl实际只有cpp文件中可见,相关的上下文变量也全部存储在Impl类中,从而实现了头文件依赖的分离.避免了各个外部模块中可能发生的冲突问题.
PS:所以说module特性什么时候流行起来呢?
PS2:怀疑肯定在Effective C++之类的书里面看过,只不过自己没注意到
PS3:是的我在弄COM的时候遇到莫名其妙的问题了….x
PS4:依然是f7(eiki)!!!
order pharmacy online egypt
stromectol for sale
best debt consolidation loans
cialis generic availability eqbddzfi http://tadedmedz.com/ cialis at a discount price
cialis headaches afterwards kktbllnu http://tadedmedz.online/ tadalafil vs cialis
payday cash advance
chloroquine 5ml
buy cialis professional
order pharmacy online egypt
plaquenil 100 mg
afoe viagra coupons http://dietkannur.org gqgz mpfv
personal loan agreement template
xfcc otc viagra http://dietkannur.org upwz vqcr
soft levitra
payday loans portland or
amoxil 250 mg
reliable canadian pharmacy
canadianpharmacy com
prices of cialis cheap cialis svqpujer online cialis
cialis samples request buy cialis hflgbkyj cialis 20 mg
best loan consolidation
male dysfunction xawzehgq buy levitra online prescription drugs
over the counter ed hrqqnfyc levitra canada compare ed drugs
cheap erectile dysfunction pills uzpddkwf buy levitra online ed treatment review
viagra no prescription cqkzauao generic viagra viagra coupon
buy female viagra uk online
lexapro escitalopram oxalate
online viagra prescription canada
generic brand augmentin
sameday loans
top personal loans
how can i get viagra
bad credit personal loans
the peoples pharmacy pharmacy in canada pharmacy orlando
purchasing viagra in usa
dexamethasone 0.25 mg tablet
viagra price mexico
erectile dysfunction pills pharmacy rx one reviews pharma
canada pharmacy reviews pharmacy coupons ed meds
drug prices
https://canadarx24.com/
herbal ed
pharmacy online pharmacy rx north drug store
buy canadian drugs
https://canadarx24.com/
causes for ed
24 hour pharmacy near me best drugstore concealer ed drugs
cash lender
cheap cialis 10mg
online pharmacy reviews dysfunction ed meds
payday loans vancouver bc
propecia pharmacy prices
mail order cialis
pharmacy discount card sex ed the pharmacy
sildenafil 200mg price
generic levitra 2018
feldene capsule 10 mg
emergency loans for veterans
Can connecting another computer to my network influence the connections of the other computers?
bystolic 10 coupon
low interest personal loans
viagra for woman
cash advance loans
how to get money fast
generic feldene
where to buy cheap viagra in usa
online personal loans instant approval
best cure for ed https://canadianpharmacyvikky.com carprofen without vet prescription
natural ed medications https://canadianpharmacyvikky.com viagra without doctor prescription
quick loans no credit check
apply for a loan
apply for
hydroxychloroquine 700
anafranil 75
tadalafil 20mg india price
lamisil cream 15g prices
stromectol ireland
fast cash loans online
lopressor generic
online installment loans
how to get cialis coupon
compare loan
where can i buy oral ivermectin
hzgyeuyt how does cialis work http://cialisirt.online/ cialis free trial
alaska loan
mmubqsgp cialis pills for sale http://cialisirt.online/ generic cialis at walgreens pharmacy
sildenafil gel 100mg
sildenafil 100mg price usa
kfhwzufo viagra online canada http://viagrastm.com/ viagra from canada
bdogdzhx canadian viagra http://viagrastm.online/ online viagra
dtgoeqgf generic viagra walmart http://viagrastm.com/ viagra no prescription
tadalafil soft tablets
personal loans application
aspirin 0.5 mg
direct lender tribal
cozaar 10mg
best price sildenafil uk
quick loans no credit
plaquenil price us
viagra 4 tablet
personal loans apply
tadalafil 5mg cost
loans with poor credit
clomid 2020 yasmin 1950 yasmin oral contraceptive
yasmin coupon buy alesse online yasmin weight loss
how to get valtrex without a prescription valtrex online usa famvir online pharmacy
viagra price per pill
installment lenders
famvir price canada buy famvir online acyclovir 800 mg buy online
serophene serophene order clomid online
can you purchase valtrex online valtrex 500mg price in india acyclovir cream cost
zithromax buy online no prescription bactrim buying natural antibiotic for cats
loans online direct
how to get sildenafil cheapest
no hassle payday loans
Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712
Taxi moto paris
Hello, i think that i saw you visited my web site thus i came to “return the favor”.I'm trying to find things to enhance my web site!I
suppose its ok to use some of your ideas!!
Here is my web-site hey
quineprox 90
alternatives to payday loans
wbjiplir buy viagra online over the counter viagra
gzliiiai buy viagra online online viagra prescription
doxazosin 2 mg daily
cheap viagra online https://cheapvgr100.com/ hopsqezd
prozac 60 mg cost
how does a payday loan work
where can i buy sildenafil 20mg
debt consolidation credit card
vardenafil tablets price
canadian online drugs cheap lipitor generic lipitor tablets
lloyds home insurance
how to purchase viagra online
generic viagra in australia
cialis generic availability buy cialis cialis vs levitra
payday loans in maryland
male erectile dysfunction lipitor for sale lipitor for sale
canadian pharmacy generic viagra buy viagra online canada walmart viagra
generic viagra online viagra pills viagra without a doctor prescription
viagra without a doctor prescription viagra cheap buy viagra
homeowner insurance quotes comparison
spotloan
viagra 50 mg pill
cenmox 250 buy Flagyl best pharmacy online
male ed drugs cheap Valtrex cheap antiviral drugs
levitra without a doctor prescription erectile dysfunction pills ed meds
buy medications online canadian mail in pharmacy pharmacy in canada ontario
omnicef allergy
margin loan
Flagyl antibiotics cheap Doxycycline how can i order prescription drugs without a doctor
noroxin 400 mg canada price
ivermectin stromectol
personal loans unsecured
homesite insurance company
ed devices pharmacies not requiring a prescription best rated canadian pharmacies
Antibiotic Alternative To Keflex Allergy Erefarly buy cialis online cheap BoosyLaw cialis from va
flood insurance quotes
200 mg viagra online
renters insurance quotes
rate canadian pharmacies
homeowner insurance quotes comparison
online viagra canada
payday loans tacoma wa
purchasing viagra in mexico
sildenafil 100mg gel
house insurance quotes comparison
allstate home insurance quote
cash advances payday loans
viagra coupons generic sildenafil roman viagra
viagra coupons
viagra coupon viagra for sale viagra over the counter usa 2020
buy viagra online cheap
over the counter viagra viagra generic for sale viagra online
where can i buy viagra
cash till payday
live webcam chat
100 mg sildenafil cost
877 cash now
usaa life insurance quote
ed pills online pharmacy: cialis without a doctor's prescription medicine for ed
how to help ed: hims ed pills ed supplements
canadian online pharmacy canadian pharmacy viagra comparison of ed drugs
herbal replacement for viagra/cialis/levitra... cialis for sale canadien cialis
mens erection pills Prednisone ed aids
side effects for cialis cialis generic free cialis medication for providers
erectile dysfunction drug cheap generic drugs from india ed treatment drugs
medication for ed canada pharmacy online ed supplements
best ed supplements buy Prednisone ed help
cialis in canada buy cialis real cialis online with paypal
cialis prices cialis online cialis for daily use
cialis coupon cialis tadalafil switching from tamsulosin to cialis
viagra prescription online generic viagra no prescription viagra
best online drugstore cheap Doxycyline home remedies for erectile dysfunction
how much will generic viagra cost viagra pill viagra viagra without a doctor prescription
ed online pharmacy canadian pharmacy viagra best ed pills non prescription
where to get viagra buy viagra generic viagra 100mg price
personal loans with no credit check personal loans for bad credit
buy tadalafil tadalafil canada
tadalafil generic tadalafil
speedy cash payday loans online payday loans
https://amoxicillingeneric500.com/ cost of amoxicillin 875 mg
https://zantacgeneric150.com/ zantac coupons
https://prednisonegeneric20.com/ prednisone 20mg nz
https://doxycylinegeneric100.com/
ed doctor cheap medication online ed meds online without doctor prescription
ed in young men
ed meds online without doctor prescription ed drugs over the counter prescription drugs canada buy online
injections for ed
pumps for ed ed drugs over the counter best ed medication
best pills for ed
cialis erection penis cheap cialis liquid cialis source reviews
cialis professional generic cialis cialis in canada
vitamins for ed Cheap Erection Pills best ed treatments
buy ed pills ED Pills canadian pharmacy online
ed cure psychological ed treatment online medication
vacuum pumps for ed generic viagra ed medications list
buy generic viagra online generic viagra online how much does viagra cost
viagra generic buy generic drugs viagra without a prescription
viagra coupons generic viagra online buy viagra
otc viagra buy ed pills online cheap generic viagra
generic for viagra buy ed pills online viagra walmart
erectile dysfunction treatment canadian online pharmacy best over the counter ed pills
over the counter viagra cvs cheap viagra generic where can i buy viagra over the counter
tadalafil vs cialis buy cialis cialis maximum dosage
buy viagra online canada buy generic viagra online online viagra prescription