Forse intendi una delle tre seguenti?
codice:#include <iostream> /* $ g++ -Wall -ansi -pedantic -Wextra -Wconversion main.cpp $ ./a.out aBase.fValue: 5; aDerivata.fValue: 10; aBase15.fValue: 15; aBase20.fValue: 20; aModello25.fValue: 25; aModello30.fValue: 30; */ namespace ig{ class Base{ public: const int fValue; public: Base (void): fValue (5){ } Base (const int theValue): fValue (theValue){ } }; class Derivata: public Base{ public: Derivata (void): Base (10){ } }; template <int TInt> class Modello{ public: const int fValue; Modello (void): fValue (TInt){ } }; } int main (void){ // one const ig::Base aBase; const ig:: Derivata aDerivata; std::cout << "aBase.fValue: " << aBase.fValue << ";" << std::endl; std::cout << "aDerivata.fValue: " << aDerivata.fValue << ";" << std::endl; // two const ig::Base aBase15 (15); const ig::Base aBase20 (20); std::cout << "aBase15.fValue: " << aBase15.fValue << ";" << std::endl; std::cout << "aBase20.fValue: " << aBase20.fValue << ";" << std::endl; // three const ig::Modello <25> aModello25; const ig::Modello <30> aModello30; std::cout << "aModello25.fValue: " << aModello25.fValue << ";" << std::endl; std::cout << "aModello30.fValue: " << aModello30.fValue << ";" << std::endl; return 0; }

Rispondi quotando