Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.84 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is the C4345 warning of Visual Studio wrong?
  2. #include <array>
  3. #include <iostream>
  4.  
  5. int main(){
  6.     static unsigned const buf_size = 5;
  7.     typedef std::array<char, buf_size> buf_type;
  8.  
  9.     char buf[] = { 5, 5, 5, 5, 5 };
  10.     void* p = &buf[0];
  11.     buf_type* pbuf = new (p) buf_type(); // <=== #10
  12.  
  13.     for(unsigned i=0; i < buf_size; ++i)
  14.         std::cout << (char)((*pbuf)[i] + 0x30) << ' ';
  15. }
  16.        
  17. buf_type* pbuf = new (p) buf_type; // note the missing '()'
  18.        
  19. // POD version.
  20. // buf_type = new (p) buf_type;
  21. typedef char buf_type;
  22. buf_type *pbuf = p;             // Pointer is assigned
  23.        
  24. // Constructed version.
  25. // buf_type = new (p) buf_type();
  26. void construct_buf_type(buf_type *what);
  27.  
  28. typedef char buf_type;
  29. buf_type *pbuf = p;             // Pointer is assigned
  30. construct_buf_type(buf_type);   // Constructor is called which default-initializes it