How can I write a constructor specifying default parameters values,
#include <iostream> using namespace std; struct foo { char *_p; int _q; foo( char *p = nullptr, int q = 0 ): _p(p), _q(q) { cout << "_q: " << _q << endl; } }; and then use it passing only some values without taking into account their order ?
E.g.: this works:
char tmp; foo f( &tmp ); but this doesn't:
foo f( 1 ); $ g++ -O0 -g -Wall -std=c++0x -o test test.cpp test.cpp: In function ‘int main(int, char**)’: test.cpp:18:11: error: invalid conversion from ‘int’ to ‘char*’ [-fpermissive] test.cpp:10:2: error: initializing argument 1 of ‘foo::foo(char*, int)’ [-fpermissive]