书籍:C++ Primer Plus (第六版)(中文版)
工具:Dev-C++ 5.11
电脑信息:Intel® Xeon® CPU E5-2603 v3 @ 1.60GHz
系统类型:64位操作系统,基于X64的处理器 windows10 专业版
第15章 友元、异常和其它
15.1 友元
实例15.1
tv.h
// tv.h -- Tv and Remote classes#ifndefTV_H_#defineTV_H_classTv{public:friendclassRemote;// Remote can access Tv private partsenum{Off,On};enum{MinVal,MaxVal=20};enum{Antenna,Cable};enum{TV,DVD};Tv(ints=Off,intmc=125):state(s),volume(5),maxchannel(mc),channel(2),mode(Cable),input(TV){}voidonoff(){state=(state==On)?Off:On;}boolison()const{returnstate==On;}boolvolup();boolvoldown();voidchanup();voidchandown();voidset_mode(){mode=(mode==Antenna)?Cable:Antenna;}voidset_input(){input=(input==TV)?DVD:TV;}voidsettings()const;// display all settingsprivate:intstate;// on or offintvolume;// assumed to be digitizedintmaxchannel;// maximum number of channelsintchannel;// current channel settingintmode;// broadcast or cableintinput;// TV or DVD};classRemote{private:intmode;// controls TV or DVDpublic:Remote(intm=Tv::TV):mode(m){}boolvolup(Tv&t){returnt.volup();}boolvoldown(Tv&t){returnt.voldown();}voidonoff(Tv&t){t.onoff();}voidchanup(Tv&t){t.chanup();}voidchandown(Tv&t){t.chandown();}voidset_chan(Tv&t,intc){t.channel=c;}voidset_mode(Tv&t){t.set_mode();}voidset_input(Tv&t){t.set_input();}};#endif// TV_H_tv.cpp
// tv.cpp -- methods for the Tv class (Remote methods are inline)#include<iostream>#include"tv.h"boolTv::volup(){if(volume<MaxVal){volume++;returntrue;}elsereturnfalse;}boolTv::voldown(){if(volume>MinVal){volume--;returntrue;}elsereturnfalse;}voidTv::chanup(){if(channel<maxchannel)channel++;elsechannel=1;}voidTv::chandown(){if(channel>1)channel--;elsechannel=maxchannel;}voidTv::settings()const{usingstd::cout;usingstd::endl;cout<<"TV is "<<(state==Off?"Off":"On")<<endl;if(state==On){cout<<"Volume setting = "<<volume<<endl;cout<<"Channel setting = "<<channel<<endl;cout<<"Mode = "<<(mode==Antenna?"antenna":"cable")<<endl;cout<<"Inpute = "<<(input==TV?"TV":"DVD")<<endl;}}usetv.cpp
// use_tv.cpp -- using the Tv and Remote classes#include<iostream>#include"tv.h"intmain(){usingstd::cout;Tv s42;cout<<"Initial settings for 42\" TV\n";s42.settings();s42.onoff();s42.chanup();cout<<"\nAdjusted settings for 42\" TV:\n";s42.chanup();cout<<"\nAdjusted settings for 42\" TV:\n";s42.settings();Remote grey;grey.set_chan(s42,10);grey.volup(s42);grey.volup(s42);cout<<"\n42\" settings after using remote:\n";s42.settings();Tvs58(Tv::On);s58.set_mode();grey.set_chan(s58,28);cout<<"\n58\" settings:\n";s58.settings();return0;}编译运行结果:
Initial settingsfor42" TV TV is Off Adjusted settingsfor42" TV:Adjusted settingsfor42" TV:TV is On Volume setting=5Channel setting=4Mode=cable Inpute=TV42" settings afterusingremote:TV is On Volume setting=7Channel setting=10Mode=cable Inpute=TV58" settings:TV is On Volume setting=5Channel setting=28Mode=antenna Inpute=TV--------------------------------Process exited after0.3577seconds withreturnvalue0请按任意键继续...实例15.2
tvfm.h
// tvfm.h -- Tv and Remote classes using a friend member#ifndefTVFM_H_#defineTVFM_H_classTv;// forward declarationclassRemote{public:enumState{Off,On};enum{MinVal,MaxVal=20};enum{Antenna,Cable};enum{TV,DVD};private:intmode;public:Remote(intm=TV):mode(m){}boolvolup(Tv&t);// prototype onlyboolvoldown(Tv&t);voidonoff(Tv&t);voidchanup(Tv&t);voidchandown(Tv&t);voidset_mode(Tv&t);voidset_input(Tv&t);voidset_chan(Tv&t,intc);};classTv{public:friendvoidRemote::set_chan(Tv&t,intc);enumState{Off,On};enum{MinVal,MaxVal=20};enum{Antenna,Cable};enum{TV,DVD};Tv(ints=Off,intmc=125):state(s),volume(5),maxchannel(mc),channel(2),mode(Cable),input(TV){}voidonoff(){state=(state==On)?Off:On;}boolison()const{returnstate==On;}boolvolup();boolvoldown();voidchanup();voidchandown();voidset_mode(){mode=(mode==Antenna)?Cable:Antenna;}voidset_input(){input=(input==TV)?DVD:TV;}voidsettings()const;private:intstate;intvolume;intmaxchannel;intchannel;intmode;intinput;};// Remote methods as inline functionsinlineboolRemote::volup(Tv&t){returnt.volup();}inlineboolRemote::voldown(Tv&t){returnt.voldown();}inlinevoidRemote::onoff(Tv&t){t.onoff();}inlinevoidRemote::chanup(Tv&t){t.chanup();}inlinevoidRemote::chandown(Tv&t){t.chandown();}inlinevoidRemote::set_mode(Tv&t){t.set_mode();}inlinevoidRemote::set_input(Tv&t){t.set_input();}inlinevoidRemote::set_chan(Tv&t,intc){t.channel=c;}#endiftv.cpp
// tv.cpp -- methods for the Tv class (Remote methods are inline)#include<iostream>#include"tvfm.h"boolTv::volup(){if(volume<MaxVal){volume++;returntrue;}elsereturnfalse;}boolTv::voldown(){if(volume>MinVal){volume--;returntrue;}elsereturnfalse;}voidTv::chanup(){if(channel<maxchannel)channel++;elsechannel=1;}voidTv::chandown(){if(channel>1)channel--;elsechannel=maxchannel;}voidTv::settings()const{usingstd::cout;usingstd::endl;cout<<"TV is "<<(state==Off?"Off":"On")<<endl;if(state==On){cout<<"Volume setting = "<<volume<<endl;cout<<"Channel setting = "<<channel<<endl;cout<<"Mode = "<<(mode==Antenna?"antenna":"cable")<<endl;cout<<"Inpute = "<<(input==TV?"TV":"DVD")<<endl;}}usetv.cpp
// use_tv.cpp -- using the Tv and Remote classes#include<iostream>#include"tvfm.h"intmain(){usingstd::cout;Tv s42;cout<<"Initial settings for 42\" TV\n";s42.settings();s42.onoff();s42.chanup();cout<<"\nAdjusted settings for 42\" TV:\n";s42.chanup();cout<<"\nAdjusted settings for 42\" TV:\n";s42.settings();Remote grey;grey.set_chan(s42,10);grey.volup(s42);grey.volup(s42);cout<<"\n42\" settings after using remote:\n";s42.settings();Tvs58(Tv::On);s58.set_mode();grey.set_chan(s58,28);cout<<"\n58\" settings:\n";s58.settings();return0;}编译运行结果:
Initial settingsfor42" TV TV is Off Adjusted settingsfor42" TV:Adjusted settingsfor42" TV:TV is On Volume setting=5Channel setting=4Mode=cable Inpute=TV42" settings afterusingremote:TV is On Volume setting=7Channel setting=10Mode=cable Inpute=TV58" settings:TV is On Volume setting=5Channel setting=28Mode=antenna Inpute=TV--------------------------------Process exited after0.1997seconds withreturnvalue0请按任意键继续...15.2 嵌套类
实例15.3
queuetp.h
// queuetp.h -- queue template with a nested class#ifndefQUEUETP_H_#defineQUEUETP_H_template<classItem>classQueueTP{private:enum{Q_SIZE=10};// Node is a nested class definitionclassNode{public:Item item;Node*next;Node(constItem&i):item(i),next(0){}};Node*front;// pointer to front of QueueNode*rear;// pointer to rear of Queueintitems;// current number of items in Queueconstintqsize;// maximum number of items in QueueQueueTP(constQueueTP&q):qsize(0){}QueueTP&operator=(constQueueTP&q){return*this;}public:QueueTP(intqs=Q_SIZE);~QueueTP();boolisempty()const{returnitems==0;}boolisfull()const{returnitems==qsize;}intqueuecount()const{returnitems;}boolenqueue(constItem&item);// add item to endbooldequeue(Item&item);// remove item from front};// QueueTP methodstemplate<classItem>QueueTP<Item>::QueueTP(intqs):qsize(qs){front=rear=0;items=0;}template<classItem>QueueTP<Item>::~QueueTP(){Node*temp;while(front!=0)// while queue is not yet empty{temp=front;// save address of front itemfront=front->next;// reset pointer to next itemdeletetemp;// delete former front}}// Add item to queuetemplate<classItem>boolQueueTP<Item>::enqueue(constItem&item){if(isfull())returnfalse;Node*add=newNode(item);// create node// on failure, new throws std::bad_alloc exceptionitems++;if(front==0)// if queue is empty,front=add;// place item at frontelserear->next=add;// else place at rearrear=add;// have rear point to new nodereturntrue;}// Place front item into item variable and remove from queuetemplate<classItem>boolQueueTP<Item>::dequeue(Item&item){if(front==0)returnfalse;item=front->item;// set item to first item in queueitems--;Node*temp=front;// save location of first itemfront=front->next;// reset front to next itemdeletetemp;// delete former first itemif(items==0)rear=0;returntrue;}#endifnested.cpp
// nested.cpp -- using a queue that has a nested class#include<iostream>#include<string>#include"queuetp.h"intmain(){usingstd::string;usingstd::cin;usingstd::cout;QueueTP<string>cs(5);string temp;while(!cs.isfull()){cout<<"Please enter your name. You will be ""served in the order of arrival.\n""name: ";getline(cin,temp);cs.enqueue(temp);}cout<<"The queue is full. Processing begins!\n";while(!cs.isempty()){cs.dequeue(temp);cout<<"Now processing "<<temp<<"...\n";}// cin.get();return0;}编译运行结果:
Please enter your name.You will be served in the order of arrival.name:sfsg vfh Please enter your name.You will be served in the order of arrival.name:fhf Please enter your name.You will be served in the order of arrival.name:bmbm Please enter your name.You will be served in the order of arrival.name:,j,jl;Please enter your name.You will be served in the order of arrival.name:hjggj The queue is full.Processing begins!Now processing sfsg vfh...Now processing fhf...Now processing bmbm...Now processing,j,jl;...Now processing hjggj...--------------------------------Process exited after28.36seconds withreturnvalue0请按任意键继续...15.3 异常
实例15.4
error1.cpp
//error1.cpp -- using the abort() function#include<iostream>#include<cstdlib>doublehmean(doublea,doubleb);intmain(){doublex,y,z;std::cout<<"Enter two numbers: ";while(std::cin>>x>>y){z=hmean(x,y);std::cout<<"Harmonic mean of "<<x<<" and "<<y<<" is "<<z<<std::endl;std::cout<<"Enter next set of numbers <q to quit>: ";}std::cout<<"Bye!\n";return0;}doublehmean(doublea,doubleb){if(a==-b){std::cout<<"untenable arguments to hmean()\n";std::abort();}return2.0*a*b/(a+b);}编译运行结果:
Enter two numbers:2376Harmonic mean of23and76is35.3131Enter next set of numbers<q to quit>:2352Harmonic mean of23and52is31.8933Enter next set of numbers<q to quit>:q Bye!--------------------------------Process exited after28.36seconds withreturnvalue0请按任意键继续...实例15.5
error2.cpp
//error2.cpp -- returning an error code#include<iostream>#include<cfloat>// (or float.h) for DBL_MAXboolhmean(doublea,doubleb,double*ans);intmain(){doublex,y,z;std::cout<<"Enter two numbers: ";while(std::cin>>x>>y){if(hmean(x,y,&z))std::cout<<"Harmonic mean of "<<x<<" and "<<y<<" is "<<z<<std::endl;elsestd::cout<<"One value should not be the negative "<<"of the other - try again.\n";std::cout<<"Enter next set of numbers <q to quit>: ";}std::cout<<"Bye!\n";return0;}boolhmean(doublea,doubleb,double*ans){if(a==-b){*ans=DBL_MAX;returnfalse;}else{*ans=2.0*a*b/(a+b);returntrue;}}编译运行结果:
Enter two numbers:1245Harmonic mean of12and45is18.9474Enter next set of numbers<q to quit>:3467Harmonic mean of34and67is45.1089Enter next set of numbers<q to quit>:q Bye!--------------------------------Process exited after10.52seconds withreturnvalue0请按任意键继续...实例15.6
error3.cpp
// error3.cpp -- using an exception#include<iostream>doublehmean(doublea,doubleb);intmain(){doublex,y,z;std::cout<<"Enter two numbers: ";while(std::cin>>x>>y){try{// start of try blockz=hmean(x,y);}// end of try blockcatch(constchar*s)// start of exception handler{std::cout<<s<<std::endl;std::cout<<"Enter a new pair of numbers: ";continue;}// end of handlerstd::cout<<"Harmonic mean of "<<x<<" and "<<y<<" is "<<z<<std::endl;std::cout<<"Enter next set of numbers <q to quit>: ";}std::cout<<"Bye!\n";return0;}doublehmean(doublea,doubleb){if(a==-b)throw"bad hmean() arguments: a = -b not allowed";return2.0*a*b/(a+b);}编译运行结果:
Enter two numbers:2345Harmonic mean of23and45is30.4412Enter next set of numbers<q to quit>:10-5Harmonic mean of10and-5is-20Enter next set of numbers<q to quit>:10-10badhmean()arguments:a=-bnotallowed Enter anewpair of numbers:119Harmonic mean of1and19is1.9Enter next set of numbers<q to quit>:q Bye!--------------------------------Process exited after57.21seconds withreturnvalue0请按任意键继续...实例15.7
exc_mean.h
// exc_mean.h -- exception classes for hmean(), gmean()#include<iostream>classbad_hmean{private:doublev1;doublev2;public:bad_hmean(doublea=0,doubleb=0):v1(a),v2(b){}voidmesg();};inlinevoidbad_hmean::mesg(){std::cout<<"hmean("<<v1<<", "<<v2<<"): "<<"invalid arguments: a = -b\n";}classbad_gmean{public:doublev1;doublev2;bad_gmean(doublea=0,doubleb=0):v1(a),v2(b){}constchar*mesg();};inlineconstchar*bad_gmean::mesg(){return"gmean() arguments should be >= 0\n";}error4.cpp
//error4.cpp using exception classes#include<iostream>#include<cmath>// or math.h, unix users may need -lm flag#include"exc_mean.h"// function prototypesdoublehmean(doublea,doubleb);doublegmean(doublea,doubleb);intmain(){usingstd::cout;usingstd::cin;usingstd::endl;doublex,y,z;cout<<"Enter two numbers: ";while(cin>>x>>y){try{// start of try blockz=hmean(x,y);cout<<"Harmonic mean of "<<x<<" and "<<y<<" is "<<z<<endl;cout<<"Geometric mean of "<<x<<" and "<<y<<" is "<<gmean(x,y)<<endl;cout<<"Enter next set of numbers <q to quit>: ";}// end of try blockcatch(bad_hmean&bg)// start of catch block{bg.mesg();cout<<"Try again.\n";continue;}catch(bad_gmean&hg){cout<<hg.mesg();cout<<"Values used: "<<hg.v1<<", "<<hg.v2<<endl;cout<<"Sorry, you don't get to play any more.\n";break;}// end of catch block}cout<<"Bye!\n";// cin.get();// cin.get();return0;}doublehmean(doublea,doubleb){if(a==-b)throwbad_hmean(a,b);return2.0*a*b/(a+b);}doublegmean(doublea,doubleb){if(a<0||b<0)throwbad_gmean(a,b);returnstd::sqrt(a*b);}编译运行结果:
Enter two numbers:1215Harmonic mean of12and15is13.3333Geometric mean of12and15is13.4164Enter next set of numbers<q to quit>:126Harmonic mean of12and6is8Geometric mean of12and6is8.48528Enter next set of numbers<q to quit>:5-5hmean(5,-5):invalid arguments:a=-b Try again.5-2Harmonic mean of5and-2is-6.66667gmean()arguments should be>=0Values used:5,-2Sorry,you don't get to play any more.Bye!--------------------------------Process exited after50.71seconds withreturnvalue0请按任意键继续...实例15.8
error5.cpp
//error5.cpp -- unwinding the stack#include<iostream>#include<cmath>// or math.h, unix users may need -lm flag#include<string>#include"exc_mean.h"classdemo{private:std::string word;public:demo(conststd::string&str){word=str;std::cout<<"demo "<<word<<" created\n";}~demo(){std::cout<<"demo "<<word<<" destroyed\n";}voidshow()const{std::cout<<"demo "<<word<<" lives!\n";}};// function prototypesdoublehmean(doublea,doubleb);doublegmean(doublea,doubleb);doublemeans(doublea,doubleb);intmain(){usingstd::cout;usingstd::cin;usingstd::endl;doublex,y,z;{demod1("found in block in main()");cout<<"Enter two numbers: ";while(cin>>x>>y){try{// start of try blockz=means(x,y);cout<<"The mean mean of "<<x<<" and "<<y<<" is "<<z<<endl;cout<<"Enter next pair: ";}// end of try blockcatch(bad_hmean&bg)// start of catch block{bg.mesg();cout<<"Try again.\n";continue;}catch(bad_gmean&hg){cout<<hg.mesg();cout<<"Values used: "<<hg.v1<<", "<<hg.v2<<endl;cout<<"Sorry, you don't get to play any more.\n";break;}// end of catch block}d1.show();}cout<<"Bye!\n";// cin.get();// cin.get();return0;}doublehmean(doublea,doubleb){if(a==-b)throwbad_hmean(a,b);return2.0*a*b/(a+b);}doublegmean(doublea,doubleb){if(a<0||b<0)throwbad_gmean(a,b);returnstd::sqrt(a*b);}doublemeans(doublea,doubleb){doubleam,hm,gm;demod2("found in means()");am=(a+b)/2.0;// arithmetic meantry{hm=hmean(a,b);gm=gmean(a,b);}catch(bad_hmean&bg)// start of catch block{bg.mesg();std::cout<<"Caught in means()\n";throw;// rethrows the exception}d2.show();return(am+hm+gm)/3.0;}编译运行结果:
demo found in block inmain()created Enter two numbers:125demo found inmeans()created demo found inmeans()lives!demo found inmeans()destroyed The mean mean of12and5is7.76826Enter next pair:6-6demo found inmeans()createdhmean(6,-6):invalid arguments:a=-b Caught inmeans()demo found inmeans()destroyedhmean(6,-6):invalid arguments:a=-b Try again.6-8demo found inmeans()created demo found inmeans()destroyedgmean()arguments should be>=0Values used:6,-8Sorry,you don't get to play any more.demo found in block inmain()lives!demo found in block inmain()destroyed Bye!--------------------------------Process exited after25.07seconds withreturnvalue0请按任意键继续...实例15.9
newexcp.cpp
// newexcp.cpp -- the bad_alloc exception#include<iostream>#include<new>#include<cstdlib>// for exit(), EXIT_FAILUREusingnamespacestd;structBig{doublestuff[20000];};intmain(){Big*pb;try{cout<<"Trying to get a big block of memory:\n";pb=newBig[10000];// 1,600,000,000 bytescout<<"Got past the new request:\n";}catch(bad_alloc&ba){cout<<"Caught the exception!\n";cout<<ba.what()<<endl;exit(EXIT_FAILURE);}cout<<"Memory successfully allocated\n";pb[0].stuff[0]=4;cout<<pb[0].stuff[0]<<endl;delete[]pb;// cin.get();return0;}编译运行结果:
Trying to get a big block of memory:Got past thenewrequest:Memory successfully allocated4--------------------------------Process exited after0.3715seconds withreturnvalue0请按任意键继续...实例15.10
sales.h
// sales.h -- exceptions and inheritance#include<stdexcept>#include<string>classSales{public:enum{MONTHS=12};// could be a static constclassbad_index:publicstd::logic_error{private:intbi;// bad index valuepublic:explicitbad_index(intix,conststd::string&s="Index error in Sales object\n");intbi_val()const{returnbi;}virtual~bad_index()throw(){}};explicitSales(intyy=0);Sales(intyy,constdouble*gr,intn);virtual~Sales(){}intYear()const{returnyear;}virtualdoubleoperator[](inti)const;virtualdouble&operator[](inti);private:doublegross[MONTHS];intyear;};classLabeledSales:publicSales{public:classnbad_index:publicSales::bad_index{private:std::string lbl;public:nbad_index(conststd::string&lb,intix,conststd::string&s="Index error in LabeledSales object\n");conststd::string&label_val()const{returnlbl;}virtual~nbad_index()throw(){}};explicitLabeledSales(conststd::string&lb="none",intyy=0);LabeledSales(conststd::string&lb,intyy,constdouble*gr,intn);virtual~LabeledSales(){}conststd::string&Label()const{returnlabel;}virtualdoubleoperator[](inti)const;virtualdouble&operator[](inti);private:std::string label;};sales.cpp
// sales.cpp -- Sales implementation#include"sales.h"usingstd::string;Sales::bad_index::bad_index(intix,conststring&s):std::logic_error(s),bi(ix){}Sales::Sales(intyy){year=yy;for(inti=0;i<MONTHS;++i)gross[i]=0;}Sales::Sales(intyy,constdouble*gr,intn){year=yy;intlim=(n<MONTHS)?n:MONTHS;inti;for(i=0;i<lim;++i)gross[i]=gr[i];// for i > n and i < MONTHSfor(;i<MONTHS;++i)gross[i]=0;}doubleSales::operator[](inti)const{if(i<0||i>=MONTHS)throwbad_index(i);returngross[i];}double&Sales::operator[](inti){if(i<0||i>=MONTHS)throwbad_index(i);returngross[i];}LabeledSales::nbad_index::nbad_index(conststring&lb,intix,conststring&s):Sales::bad_index(ix,s){lbl=lb;}LabeledSales::LabeledSales(conststring&lb,intyy):Sales(yy){label=lb;}LabeledSales::LabeledSales(conststring&lb,intyy,constdouble*gr,intn):Sales(yy,gr,n){label=lb;}doubleLabeledSales::operator[](inti)const{if(i<0||i>=MONTHS)thrownbad_index(Label(),i);returnSales::operator[](i);}double&LabeledSales::operator[](inti){if(i<0||i>=MONTHS)thrownbad_index(Label(),i);returnSales::operator[](i);}use_sales.cpp
// use_sales.cpp -- nested exceptions#include<iostream>#include"sales.h"intmain(){usingstd::cout;usingstd::cin;usingstd::endl;doublevals1[12]={1220,1100,1122,2212,1232,2334,2884,2393,3302,2922,3002,3544};doublevals2[12]={12,11,22,21,32,34,28,29,33,29,32,35};Salessales1(2011,vals1,12);LabeledSalessales2("Blogstar",2012,vals2,12);cout<<"First try block:\n";try{inti;cout<<"Year = "<<sales1.Year()<<endl;for(i=0;i<12;++i){cout<<sales1[i]<<' ';if(i%6==5)cout<<endl;}cout<<"Year = "<<sales2.Year()<<endl;cout<<"Label = "<<sales2.Label()<<endl;for(i=0;i<=12;++i){cout<<sales2[i]<<' ';if(i%6==5)cout<<endl;}cout<<"End of try block 1.\n";}catch(LabeledSales::nbad_index&bad){cout<<bad.what();cout<<"Company: "<<bad.label_val()<<endl;cout<<"bad index: "<<bad.bi_val()<<endl;}catch(Sales::bad_index&bad){cout<<bad.what();cout<<"bad index: "<<bad.bi_val()<<endl;}cout<<"\nNext try block:\n";try{sales2[2]=37.5;sales1[20]=23345;cout<<"End of try block 2.\n";}catch(LabeledSales::nbad_index&bad){cout<<bad.what();cout<<"Company: "<<bad.label_val()<<endl;cout<<"bad index: "<<bad.bi_val()<<endl;}catch(Sales::bad_index&bad){cout<<bad.what();cout<<"bad index: "<<bad.bi_val()<<endl;}cout<<"done\n";// std::cin.get();return0;}编译运行结果:
Compiling single file...---------Filename:C:\C++Primer Plaus\example\use_sales.cpp-Compiler Name:TDM-GCC4.9.264-bit Release Processing C++source file...---------C++Compiler:C:\ProgramFiles(x86)\Dev-Cpp\MinGW64\bin\g++.exe-Command:g++.exe"C:\C++Primer Plaus\example\use_sales.cpp"-o"C:\C++Primer Plaus\example\use_sales.exe"-std=c++11-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include"-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include"-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include"-I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++"-L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib"-L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib"-static-libgcc C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.text+0x183):undefined reference to `Sales::Sales(int,doubleconst*,int)' C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.text+0x1dd):undefined reference to `LabeledSales::LabeledSales(std::stringconst&,int,doubleconst*,int)' C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.rdata$.refptr._ZN12LabeledSalesixEi[.refptr._ZN12LabeledSalesixEi]+0x0):undefined reference to `LabeledSales::operator[](int)' C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.rdata$.refptr._ZN5SalesixEi[.refptr._ZN5SalesixEi]+0x0):undefined reference to `Sales::operator[](int)' C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.rdata$.refptr._ZTV12LabeledSales[.refptr._ZTV12LabeledSales]+0x0):undefined reference to `vtableforLabeledSales'C:\Users\wusq2000\AppData\Local\Temp\cc8fICBP.o:use_sales.cpp:(.rdata$.refptr._ZTV5Sales[.refptr._ZTV5Sales]+0x0):undefined reference to `vtableforSales'collect2.exe:error:ld returned1exit status Compilation results...---------Errors:1-Warnings:0-Compilation Time:1.30s