0% found this document useful (0 votes)
23 views4 pages

Cod 18

The document includes code examples demonstrating C++ concepts like namespaces, classes, templates, and inheritance. It defines classes like INT, OM, and var that demonstrate class features and uses namespaces to distinguish between variables with the same name. Main function tests the var class template by creating instances of different data types and outputs their values.

Uploaded by

Mihaela Guja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Cod 18

The document includes code examples demonstrating C++ concepts like namespaces, classes, templates, and inheritance. It defines classes like INT, OM, and var that demonstrate class features and uses namespaces to distinguish between variables with the same name. Main function tests the var class template by creating instances of different data types and outputs their values.

Uploaded by

Mihaela Guja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <iostream>

#include <iomanip>
#include <cstdlib>
#include <ctime>

#include <string>
#include <cstring>

#include <conio.h>
#include <fstream>

using namespace std;


/*

//using std::cout;
//using std::endl;

int a=777;

namespace propriul_namespace_itstep_2022
{

int a=111;

namespace yyy
{
int a=333;

namespace zzz
{
int a=444;
}

namespace PNI = propriul_namespace_itstep_2022;

*/

/*

1. namespace
2. static
3. clase abstracte
4. clase template

*/

/*
class INT
{
int value;
public:
INT(int value=NULL):value(value){ }
INT(const INT &OBJECT ):value(OBJECT.value) { }
~INT(){}

inline void setVALUEm(char *mess){ cout<<mess; cin>>this->value;}


inline void setVALUEa(int value){ this->value = value ; }
inline const int getVALUE()const{ return this->value; }
};

*/
/*
class yyy
{

public:

static int y;
void fy(){ cout<<" y = "<<y<<endl;}

};

class xxx : public yyy


{

public:
static int x;
void fx(){ cout<<" x = "<<x<<endl;}

};

int xxx::x;
int yyy::y;

*/
/*
class OMabs
{
public:
virtual void gen() = 0 ; // metoda virtuala putra
virtual void nume() = 0 ;
};

class OM : public OMabs


{
public:
void f();
void gen(){ cout<<" gen "<<endl; } // metoda virtuala putra
void nume(){ cout<<" nume "<<endl; }
};
*/

//template <typename T>


//void fun( T xxx);
template <class T, class T1, class T2>
class var
{
T value;

public:
var(T value=NULL):value(value){ }
var(const var &OBJECT ):value(OBJECT.value) { }
~var(){}

inline void setVALUEm(char *mess){ cout<<mess; cin>>this->value;}


inline void setVALUEa(T value){ this->value = value ; }
inline const T getVALUE()const{ return this->value; }
};

int main()
{

var <int,string,double> INT=123;

cout<<" INT = "<<INT.getVALUE()<<endl;

var <double,double,double> DOUBLE=123.321;

cout<<" DOUBLE = "<<DOUBLE.getVALUE()<<endl;

var <char,char,double> CHAR='a';

cout<<" CHAR = "<<CHAR.getVALUE()<<endl;

var <string,string,double> STRING("step");

cout<<" STRING = "<<STRING.getVALUE()<<endl;

/// ERROR OMabs X;

/*
OM a;

a.gen();
a.nume();

*/

/*
xxx A,B,C[1000];

A.x=7777;

A.fx();
B.fx();
B.x=888;

A.fx();
B.fx();
*/

/*
cout<<" step 2022 a="<<a<<endl;

cout<<" propriul_namespace_itstep_2022 =
"<<propriul_namespace_itstep_2022::a<<endl;

cout<<" PNI = "<<PNI::yyy::zzz::a<<endl;

*/

/// 1. namespace a+b-c toate var si fun se numesc a - mininm 3 fun

return 0;
}

You might also like