Created
January 18, 2012 23:05
-
-
Save sinannar/1636383 to your computer and use it in GitHub Desktop.
where is the error if there is error- c++ example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
//#define TEST1 //yanlıs obje olusmaz | |
//#define TEST2 //yanlıs A da c dıe bısı yok | |
//#define TEST3 //yanlıs upcasting downcasting olayı | |
//#define TEST4 //calısıo | |
//#define TEST5 //yanlıs templatelık | |
class A | |
{ | |
public: | |
A(): a(-1), b(-2){} | |
virtual void f1() = 0; | |
int a; | |
int b; | |
}; | |
class B: public A | |
{ | |
public: | |
B(): b(1), c(2) {} | |
void f1() { std::cout << a+b+c;} | |
int b; | |
int c; | |
}; | |
#ifdef TEST5 | |
template<class T> | |
class C:public B | |
{ | |
void f1() | |
{a++;} | |
}; | |
#endif | |
int main() | |
{ | |
#ifdef TEST1 | |
A v1; | |
v1.a = 10.0; | |
#endif | |
#ifdef TEST2 | |
B v2; | |
A * aPtr; | |
aPtr = &v2; | |
aPtr->f1(); | |
aPtr->c=12; | |
#endif | |
#ifdef TEST3 | |
B v2; | |
A * aPtr = &v2; | |
B * bPtr ; | |
aPtr->f1(); | |
bPtr = aPtr; | |
bPtr->f1(); | |
#endif | |
#ifdef TEST4 | |
B v2; | |
A & aRef = v2; | |
aRef.f1(); | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment