Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Last active June 12, 2017 03:00
Show Gist options
  • Save jniemann66/4168281cb786b609eca513c182028ee4 to your computer and use it in GitHub Desktop.
Save jniemann66/4168281cb786b609eca513c182028ee4 to your computer and use it in GitHub Desktop.

typeid, typeof, decltype etc ...

typeid is an operator in C++ which returns a std::type_info object representing dynamic information about an object at runtime

Requires the <typeinfo> header to be included.

class type_info {
public:
  virtual ~type_info();
  bool operator==(const type_info& rhs) const noexcept;
  bool operator!=(const type_info& rhs) const noexcept;
  bool before(const type_info& rhs) const noexcept;
  size_t hash_code() const noexcept;
  const char* name() const noexcept;
  type_info(const type_info& rhs) = delete; // cannot be copied
  type_info& operator=(const type_info& rhs) = delete; // cannot be copied
};

typeof is a compiler-specific extension (not part of C++) which yields the compile-time type of an object

decltype (Since C++11) is a specifier which can be used to specify a type by inspecting the type of a a given entity or expression.

decltype should be used instead of typeof for portable code.

__declspec is a Microsoft-specific extension, most commonly used to import/export symbols from/to dlls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment