AA: P1000 [[primer]]
Q: find intersection of 2 compatible vectors?
Q: can you pass a float into a func(int) or func(char)?
AA: yes but if you cout in func(), it interprets and prints the object differently.
Q: can a non-static reference field be initialized upon declaration?
%%A: i don’t think so, reference field or nonref. The java-style quick initi is illegal for non-static.
AA: gcc allows java-style init only for a static AND const field.
Q: can you “extern” a prototype and then declare the same prototype again?
Q[u]:difference between “new Account” and “new Account()” with the parentheses?
A: subtle difference. See other posts on this blog such as http://bigblog.tanbin.com/2012/07/default-initializevalue-initialize-new.html
Q[u]: declare a pointer to a method accepting an int and returning void. Need to memorize the exact syntax
AA: void (Dog::*ptr2method) (int);
Q: my ex spec mentions std::runtime_error. Can I throw a range_error, or an std::exception, or std::invalid_argument?
Q: reverse print a string using copy to cout
AA: copy(str.rbegin(), str.rend(), ostream_iterator< char >(cout, ” “));
* The ” ” 2nd argument is not necessary, but I’d suggest we memorize just a single form of the ostream_iterator ctor, the 2-arg form.
* The type is char not ptr-to-char
Q: using N1::f; f(); using N2::f; f();
AA: GCC complains 2nd all to f() is ambiguous. http://www.cplusplus.com/doc/tutorial/namespaces/ explains
Q[u]: multiple inheritance dreaded diamond – what if one of the 2 “virtual” keywords is omitted? How many times will you call the base constructor?
Q[u]: anything wrong with
Base & var = static_cast(*(new Derived));
AA: legal in gcc.
[u = unimportant/trivial/unlikely to be issue in practice. Often compiler will inform you clearly.]