Curs 6 Flashcards
class A { public: int a1, a2, a3; };
class B { public: int b1, b2; };
class C : private A, private B { public: int c1, c2; };
void main(void)
{
C c;
A* a = &c;
}
11
no
derivarea e privata
error C2243: ‘type cast’: conversion from
‘C *’ to ‘A *’ exists, but is inaccessible
class A { public: int a1, a2, a3; };
class B { public: int b1, b2; };
class C : private A, private B { public: int c1, c2; };
void main(void)
{
C c;
A* a = reinterpret_cast<A*> (&c);
}
25
yes
This code will compile. It is important to understand the reinterpret_cast is
not bounded by class type or access modifier type.
int x = reinterpret_cast <int>(1000);</int>
26
eroare
int y = 100;
int x = reinterpret_cast <int>(y);</int>
26
eroare
int x = reinterpret_cast<int>(“test”);</int>
26
yes
char x = reinterpret_cast<char>(“test”);</char>
26
yes cu warning trunchiere date
float x = reinterpret_cast<float>(1.2f);</float>
27
eroare
double x = reinterpret_cast<double>(1.2);</double>
27
eroare
int number = 10;
reinterpret_cast<int &>(number) = 20;
27
yes
int number = 10;
reinterpret_cast<char &>(number) = 20;
27
yes
int x = static_cast<int>(1000);</int>
30
yes
char x = static_cast<char>(1000);</char>
30
yes
232=1000%256
char x = static_cast<char>(3.75);</char>
30
yes
3=int(3.75)
char x = static_cast<char>("test");</char>
30
eroare
const char * x = static_cast<const char *>(9);
30
eroare
class A { public: int a1, a2, a3; };
class B { public: int b1, b2; };
void main(void)
{
B b;
A* a = static_cast<A *>(&b);
}
31
eroare