Linked Questions

2065 votes
8 answers
961k views

I've been writing C and C++ code for almost twenty years, but there's one aspect of these languages that I've never really understood. I've obviously used regular casts i.e. MyClass *m = (MyClass *)...
Graeme Perrow's user avatar
307 votes
7 answers
186k views

Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is there any sort of speed difference?
dicroce's user avatar
  • 47.1k
72 votes
1 answer
68k views

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? I'm using c function in c++, where a structure passed as a void type argument in c is directly stored that ...
HariHaraSudhan's user avatar
51 votes
2 answers
76k views

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? With this C++ code, char* a = (char*) b; I got warning warning: use of old-style cast. What would be the ...
prosseek's user avatar
  • 193k
11 votes
4 answers
27k views

In C++ we can convert child class pointer to parent, but is there any way to convert it back: from parent, which was obtained from child, give child class back? I mean: class Parent { ... }; ...
user2160982's user avatar
27 votes
2 answers
35k views

What is the best practice for casting between the different number types? Types float, double, int are the ones I use the most in C++. An example of the options where f is a float and n is a double ...
keith's user avatar
  • 5,382
8 votes
3 answers
3k views

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? I have done a lot of googling to find about: why to use C++ casting operators over traditional C style ...
Rishi Mehta's user avatar
6 votes
4 answers
8k views

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? Until a few days ago, I've always used C style type casting in C++ because it seemed to work good. I ...
Brad's user avatar
  • 253
2 votes
1 answer
1k views

(I know this is very similar to some other questions on here, but I haven't found any that specifically, language-lawyerly, answer this precise detail. Most of the near-duplicates are just asking ...
Quuxplusone's user avatar
  • 28.7k
4 votes
2 answers
605 views

Quoting from item 45 in C++ Gotchas: First a dynamic_cast is not necessarily dynamic, in that it may not perform a runtime check. When performing a dynamic_cast from a derived class pointer (or ...
user997112's user avatar
  • 31.1k
0 votes
1 answer
2k views

In g++ , element access operator for const std::vector<> is defined as follows: (/usr/include/c++/7.1.1/bits/stl_vector.h) /** * @brief Subscript access to the data contained in the %vector. ...
R. F. Luis's user avatar
-2 votes
3 answers
1k views

class Base { public: virtual void print (){cout<<"Base"<<endl;} }; class Derived :public Base { public: virtual void print (){cout<<"Derived"<<...
user3476562's user avatar
0 votes
2 answers
214 views

I am using C++ to write some components in a toy x86 kernel, and I was in a situation where I had to downcast a pointer type. I had an interface and its implementation like this, class ITerminalWriter ...
Zombies are Real's user avatar
4 votes
2 answers
861 views

I'm new to C++ and reading some code as follows: template<typename T> std::istream & read(std::istream* stream, T& value){ return stream->read(reinterpret_cast<char*>(&...
Foredoomed's user avatar
  • 2,249
-2 votes
1 answer
682 views

I used a static_cast to polymorphism. I read that I should use dynamic_cast, but I can't get why. Code works in both way (with static and dynamic cast). Could anybody show me an example with ...
KeyB0rys's user avatar
  • 524

15 30 50 per page
1
2 3 4 5
17