0

For example,

class A {};      // This is blank
class B {int i}; // This is not.

How to know if a class or a class's object is blank or not?

user1899020
  • 11,941
  • 15
  • 66
  • 130

1 Answers1

1

You need what is called "reflection". reflection is the ability to inspect a type for its methods, member etc. The "usual" kind of reflection is not possible in C++, however there are ways to do it.

I suggest you read this answer here:

How can I add reflection to a C++ application?

or this one:

Is there an easy way to tell if a class/struct has no data members?

Community
  • 1
  • 1
Yonatan Nir
  • 8,303
  • 23
  • 80
  • 156
  • I don't think reflection is the right word. It is called meta-programming. Reflection is more about query type information at runtime. – Bryan Chen Jun 20 '14 at 14:41
  • @BryanChen http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3814.html -- the feature of being able to examine the contents of C++ types at compile time is being called "compile time reflection". This is appropriate, because as a feature it lets you also implement run-time reflection (by using compile-time reflection, then metaprogram a run-time reflection system). – Yakk - Adam Nevraumont Jun 20 '14 at 14:45