Quote from: option on May 04, 2011, 02:24 PMThat's not C style. C implicitly casts void * types and C++ does not.
Also, anytime I've needed to cast something, I've now realized that I was doing it c-style? I.e.Code Selectstruct Arg *arg = (struct Arg *) malloc(sizeof(struct Arg));
void *ptr;
ptr = (struct Arg *) arg;
In C++, you must explicitly cast the return of malloc, for example. This is the single language quirk that prevents C from being a true subset of C++.
Quote from: option on May 04, 2011, 02:24 PMThis is a bad example of casting. Couldn't you come up with anything else?Code Selectconst char *c = "text";
char *str = const_cast<char *> (c);
cout << str << '\n';
Because of your novice status, I'm concerned you might actually try to cast immutable strings to char *, and end up having your program crash and burn at runtime instead of giving an informative error at compile time. Just don't do it. Always practice const correctness.
Have you considered reading a book on C++ yet? All of these questions would have been answered and more. Asking on a forum should be reserved for problems a bit less trivial.