
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.84 KB | hits: 14 | expires: Never
Is the C4345 warning of Visual Studio wrong?
#include <array>
#include <iostream>
int main(){
static unsigned const buf_size = 5;
typedef std::array<char, buf_size> buf_type;
char buf[] = { 5, 5, 5, 5, 5 };
void* p = &buf[0];
buf_type* pbuf = new (p) buf_type(); // <=== #10
for(unsigned i=0; i < buf_size; ++i)
std::cout << (char)((*pbuf)[i] + 0x30) << ' ';
}
buf_type* pbuf = new (p) buf_type; // note the missing '()'
// POD version.
// buf_type = new (p) buf_type;
typedef char buf_type;
buf_type *pbuf = p; // Pointer is assigned
// Constructed version.
// buf_type = new (p) buf_type();
void construct_buf_type(buf_type *what);
typedef char buf_type;
buf_type *pbuf = p; // Pointer is assigned
construct_buf_type(buf_type); // Constructor is called which default-initializes it