Resolution of Template Default Arguments

Resolution of Template Default Arguments - Resolution of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Resolution of Template Default Arguments Jonathan Schilling, jls@sco.com In the last issue (#024) we looked at a problem where the draft standard library relied on a non-existent feature in the draft standard language. This feature was template default arguments not getting instantiated unless used. At the meeting of the ANSI/ISO C++ standards committee just concluded in Chiswick, London, a change to the language was approved that will resolve this discrepancy. First, to recap the problem: class B { public: B(int); // class doesn't have a default constructor }; B b(19); template <class T> void f(T t1, T t2 = T()); // function has default argument void z() { f(b, b); // used to be error, under new rule is ok f(b); // error, both old and new rules } Under the old rules, the instantiation of f(b, b) occurred in the context of the definition of the template function, at which point the default argument value B::B() would be looked up, and would cause an error because it did not exist.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 2

Resolution of Template Default Arguments - Resolution of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online