static counter hmmm =]
Posted on
static counter hmmm =]
#include<iostream
using namespace std;
class test
{
public:
test()
{
count++;
}
~test()
{
count--;
}
static int getCount()
{
return count;
}
/* test& getK(int a)
{
k=a;
return *this;
}
*/
private:
static int count;
// int k;
};
int test::count=0;
int main()
{
{
test *b; // pointer atanır nesne oluşmaz
test b1,b2;
b=new test[7]; // nesne oluştu burda
cout<<test::getCount()<<endl; // count==9
}
cout<<test::getCount()<<endl; // count==7 kalır eğer delete b
demez isek.
{
test *k; // pointer atanır nesne oluşmaz
test b1,b2;
k=new test[7]; // nesne oluştu burda
delete [] k;
}
cout<<test::getCount()<<endl; // count==7 hala çünkü burda
pointerla oluşanları sildik,üstteki count değişmedi
return 0;
}
1.midterm copy constructor belası O_o
Posted on
1.midterm copy constructor belası O_o
#include<iostream
#include<string>
using namespace std;
class car
{
public:
car():name("mercedes"),model(2013){}
car(string x,int y)
{
name=x;
model=y;
}
car(car & p) //copy constructor
{
name=p.name;
model=p.model;
}
void print()
{
cout<<name<<endl;
cout<<model<<endl;
}
private:
string name;
int model;
};
int main()
{
car a("ferrari",2010);
car b(a);
car c;
car d;
a.print();
b.print();
c.print();
d.print();
return 0;
}
adding two array list with operator+ O_O
Posted on
adding two array list with operator+ O_O
/*+ operatoru iki array list i birlestirecek sekilde (ornek:
lis1+list2 : list2 list1 in sonuna eklenecek) overload ediniz.
const List List::operator+(const List& input_list){*/
#include<iostream
using namespace std;
class Liste
{
public:
Liste(int = 10);
Liste(const Liste &);
Liste& operator+(Liste &);
int getSize() {return size;}
private:
int *ptr;
int size;
};
Liste::Liste(int aSize)
{
size=(aSize 0 ? aSize : 10 );
ptr = new int[size];
for(int i=0; i<size; i++)
{
ptr[i]=0;
}
}
Liste::Liste(const Liste &p)
{
size=p.size;
ptr = new int[size];
for(int i=0; i<size; i++)
{
ptr[i]=p.ptr[i];
}
}
Liste& Liste::operator+(Liste &d)
{
int i=size;
size=size+d.size;
Liste *c= new Liste(size);
Liste& result=*c;
int k=0;
for(k=0; k<i; k++)
{
c-ptr[k]=ptr[k];
}
k=0;
for(i; i<size; i++)
{
c-ptr[i]=d.ptr[k];
}
for(k=0; k<size; k++)
{
ptr[k]=c-ptr[k]; //copy to first array c=a+b - a has
got all the numbers
}
return result;
}
int main()
{
Liste a(5),b(4);
Liste& c=a+b;
cout<<c.getSize()<<endl;
return 0;
}
decrement & increment
Posted on
decrement & increment
//operator++ and operator--
#include<iostream>
using namespace std;
class decInc
{
public:
decInc(int m=5):k(m) { };
decInc& operator++();
decInc operator++(int);
decInc& operator--();
decInc operator--(int);
int getK()
{
return k;
}
private:
int k;
};
decInc& decInc::operator++() //++K
{
k=k+1;
return *this;
}
decInc decInc::operator++(int) //K++
{
decInc temp=*this;
k=k+1;
return temp;
}
decInc& decInc::operator--() //--K
{
k=k-1;
return *this;
}
decInc decInc::operator--(int) //K--
{
decInc temp=*this;
k=k-1;
return temp;
}
int main()
{
int x;
decInc d;
++d; // 6
d++; // still 6;
x=d.getK(); // x=7 now ;
cout<<x<<endl;
--d; // 6
d--; // 6
x=d.getK(); //x=5 now ;
cout<<x<<endl;
return 0;
}
inheritance acccess rules
Posted on
Introduction
Posted on
Introduction
detay in the detay
Posted on
detay in the detay
ALGORYHME :D
Posted on
ALGORYHME :D
Multiple inheritance example
Posted on