1 excerpt from online
2 code Examples
#include <iostream>#include<list>#include<iterator>#include<cmath>using namespacestd;classterm{ Public: Term (intCinte): Coef (c), exp (e) {}floatTermvalue (); intGetcoef () {returnCoef; } intGetexp () {returnexp; } Static voidSetX (floatx_t) {x=x_t; } intGetX () {returnx; } Private: intCoef; intexp; Static floatx;};floatterm::x=1.0;floatTerm::termvalue () {returncoef*Pow (X,EXP);}intMain () {list<Term>Poly; List<Term>:: Iterator begin,end; inti; floatresult=0;//The anonymous inner class in C + + is used here, which is an inner class of pointer type for(i=1;i<5; i++) Poly.push_back (term (i,i)); Begin=Poly.begin (); End=Poly.end (); Begin->setx (2); Do{result+=begin->Termvalue (); Begin++; } while(begin!=end); cout<<result<<Endl;}
Output Result: 98 correct
The anonymous inner class in C + + is a pointer type, and the anonymous inner class in Java is a reference type. This is to be divided clearly.
C + + anonymous class-pointers