What is an equivalent to instanceof in C++? [duplicate] - c++

This question already has answers here:
C++ equivalent of java's instanceof
(5 answers)
Closed 9 years ago.
How can I check the class type in c++?
In Java I used instanceof.
I prefer not to use dynamic cast, but only classic c++.
Is there any way?
Clarification:
It isn't a duplicate of another question in StackOverflow, since I asked how can I find it without using of dynamic_cast. In the other question, the answer was to use it. Please don't mark it as a duplicated.

There is no way to check class type without RTTI or it's home brew substitution. If application compiled without RTTI information about type is not stored anywhere.

Related

Confused by notation in boost::thread example [duplicate]

This question already has answers here:
What's the difference between parentheses and braces in c++ when constructing objects
(1 answer)
what is aggregate initialization
(2 answers)
Closed 9 months ago.
From boost libraries, I found this example
I marked a line with a red arrow, indicating the notation that is confusing me.
Is this special to boost or is this some sort of anonymous function syntax? I wasn't aware that C++ or C had such notation. I only kind of recognize it from python and java experience.

How can I Tell if a Type is a Functor? [duplicate]

This question already has answers here:
Find out whether a C++ object is callable
(8 answers)
Can std::is_invocable be emulated within C++11?
(1 answer)
Closed 3 years ago.
In c++17 I have is_invocable to match function pointers, lambdas, and functors.
But what if I'm trapped on c++14? Do I have a type trait, or can I write one, which will match all of these?
I've tried is_function but that only works on function pointers.
Yes you can, std::is_invocable is a library function which requires no compiler support. You can just rip the implementation from an STL of your choice.
For example, you can find LLVM implementation of __invokable (to which std::is_invocable forwards all the logic in LLVM's STL) here: https://android.googlesource.com/platform/ndk/+/5b3a49bdbd08775d0e6f9727221fe98946f6db44/sources/cxx-stl/llvm-libc++/libcxx/include/type_traits
(I was thinking of extracting it and posting here, but it seems to be too big for a post. On a lighter note, I find difference in spelling - invocable vs invokable - amusing.)

Reflection in C++ [duplicate]

This question already has answers here:
Why does C++ not have reflection?
(15 answers)
Closed 9 years ago.
I am currently porting a game from Cocos2d written in ObjectiveC to Cocos2d-x in C++. Now the objective C guys have used Reflection to populate modal classes from a json object. Is the same possible in C++ Can we use reflection in C++ ?
Kind Regards
As mentioned in the comments, C++ has no reflection.
The default solution is to register all the symbols that you need in an associative array, like unordered_map. Here are examples of that.

Can we create an instance of class type at the specified location in memory? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C++'s “placement new”
Can we create an instance of class type at the specified location in memory?if yes then how and where we should use such programming techniques?
Yes, we can. Use new(area) operator.
Another discussion at SO.

C++ change sort method [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C++ struct sorting
Is it possible to sort a vector in C++ according to a specified sorting method, like used in Java's Collections.sort that takes a Comparator?
Yes. See the answers to this question from this morning: C++ struct sorting
Yes, it is. Take a look here for an example.