c++11 - Default value for struct member in c++ -


it seems can not give default value struct members in c++,but find code below can compile , run, why? missing something?

struct type {     int = 0xffff; }; 

program:

#include <iostream>  using namespace std; struct type {     int = 0xffff; }; int main() {     // code goes here     type val;     std::cout << val.i << std::endl;      return 0; } 

it going depend on compiler use.

for gcc , clang need pass flag -std=c++11 compiler.

support member initializer , other c++11 features:

  • gcc since 4.7. see here.
  • clang since 3.0. see here.
  • visual studio compiler in 2013 version. see here.

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -