Re: Is this kind of static polymorphism valid?
Am 06.09.2012 00:02, schrieb DeMarcus:
On 2012-09-05 09:48, Daniel Kr?gler wrote:
[2nd attempt after 24 hours]
It also seems that this elaborated-type-specifier can have the same
name in different cpp files without getting 'multiple definitions'
during linkage (I found the following).
?3.3.2/6 saying "-for an /elaborated-type-specifier/ of the form
/class-key identifier/ if the /elaborated-type-specifier/ is used in
[..] otherwise, except as a friend declaration, the identifier is
declared in the smallest namespace or block scope that contains the
Is my interpretation of the standard correct if I say that as long as
the template is declared in an unnamed namespace then I can do the
specialization with the same elaborated-type-specifier name as in
another file (more or less the same as with variable names, right)?
As the wording says: The name of the type is declared in the unnamed
namespace. These are required to be unique for different translation
units, so if you have only one such variable definition and template
specialization definition per translation unit, this is well-defined.
Also another question I have is why I can't put the specialized
runTests() function within the unnamed namespace as well?
The language requires that a specialization needs to be provided in the
same namespace as the namespace of the original (primary) template
([temp.expl.spec] p2). In your example, template MyTestFixture is
defined in the global namespace, this means any specialization
needs to be provided in the same (global) namespace as well.
HTH & Greetings from Bremen,
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]