-1

AFAIK, C++ offers destructors for primitive types for consistency reason. But that doesn't work for bool type.

bool*   vptr;
vptr->~bool();  // Error. "Expected a class name after '~' to name a destructor"

int8_t* vptr;
vptr->~int8_t(); // No error.

What's wrong with my code? Here's my compiler version.

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

7

Because bool, like all other builtin types, is not a class type, though it works for typedefs and template arguments because the Standard allows it to enable generic programming.

template<typename T>
void destruct(T const & obj)
{
     obj.~T();
}

You can call this function for builtin types as well! :-)

Nawaz
  • 353,942
  • 115
  • 666
  • 851