Alf said:
* Gianni Mariani: ....
I fail to see the "lot more to it than that".
Nice try. First, you understood that it was a meta-programming question
- many programmers would not. Second, the three most recent versions of
compilers I have don't like the code - which tells me either you didn't
try it or the three compilers I used are broken. If it's a case of not
trying your code, then, I am more interested in candidates that are more
rigorous. That's just the beginning, wait ... there's more.
MSVC 2k3 says:
bit_count_alf.cpp
bit_count_alf.cpp(10) : error C2065: 'value' : undeclared identifier
bit_count_alf.cpp(10) : see reference to class template
instantiation 'BitsSetIn_<T,value_>::BitsSetInAux_<n_>' being compiled
with
[
T=int,
value_=-2,
n_=-1
]
bit_count_alf.cpp(20) : see reference to class template
instantiation 'BitsSetIn_<T,value_>::BitsSetInAux_<n_>' being compiled
with
[
T=int,
value_=-2,
n_=-2
]
bit_count_alf.cpp(27) : see reference to class template
instantiation 'BitsSetIn_<T,value_>' being compiled
with
[
T=int,
value_=-2
]
bit_count_alf.cpp(10) : error C2056: illegal expression
http://www.comeaucomputing.com/tryitout/
says:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++
"ComeauTest.c", line 13: error: explicit specialization is not allowed
in the
current scope
template<>
^
"ComeauTest.c", line 10: error: constant value is not known
(n_ % 2) + BitsSetInAux_<n_ >> 1>::value;
^
detected during:
instantiation of class "BitsSetIn_<T,
value_>::BitsSetInAux_<n_>
[with T=int, value_=-2, n_=-1]" at line 10
instantiation of class "BitsSetIn_<T,
value_>::BitsSetInAux_<n_>
[with T=int, value_=-2, n_=-2]" at line 20
instantiation of class
"BitsSetIn_<T, value_> [with T=int, value_=-2]"
at line
27
2 errors detected in the compilation of "ComeauTest.c".
and GCC says
bit_count_alf.cpp:13: error: invalid explicit specialization before ‘>’
token
bit_count_alf.cpp:13: error: explicit specialization in non-namespace
scope ‘class BitsSetIn_<T, value_>’
bit_count_alf.cpp:13: error: enclosing class templates are not
explicitly specialized
bit_count_alf.cpp:14: error: template parameters not used in partial
specialization:
bit_count_alf.cpp:14: error: ‘T’
bit_count_alf.cpp:14: error: ‘value_’
bit_count_alf.cpp: In instantiation of ‘BitsSetIn_<int,
-0x000000002>::BitsSetInAux_<-0x000000001>’:
bit_count_alf.cpp:10: instantiated from ‘BitsSetIn_<int,
-0x000000002>::BitsSetInAux_<-0x000000002>’
bit_count_alf.cpp:20: instantiated from ‘BitsSetIn_<int, -0x000000002>’
bit_count_alf.cpp:27: instantiated from here
bit_count_alf.cpp:10: error: incomplete type ‘BitsSetIn_<int,
[snip]
I thought it was only std::endl that was not defined in ostream.
Presumably you mean "not defined in <iostream>", since what you write
doesn't make sense.
Assuming that: no, your perception was incorrect regarding the normative
text of the standard (the non-normative examples are defective).
<iostream> only gives 'extern' declarations for 'std::cout' etc.
Not quite - you only got 50% of the answer. You got the gimme answer.
What is the other 50%, and what is a "gimme" answer.
What happens after B's construction ?
A "gimme putt" in golf is an easy "tap in" putt.
Why I think _what_ is a problem?
There is somthing much more fundamentally wrong here. The generated
constructor (in this case) is perfectly fine. As to why we don't place
accessor functions around members. I think that's more of a religion
question and if you have somthing more than that to say, I'd like to
know, I don't mind being wrong...
If you mean, why is it impossible to say what could be wrong without
knowing the functionality of the things used, well, that could be the
exception to the rule that there are no stupid questions.
I know this is not a case where you're interested in the job, but I
suspect that a few minutes of research would yield your unknowns.
If you mean, why is it a problem to expose public data members and not
use constructors, I think you should ask that question in
[comp.programming], because it's a newbie design-level / general OOP
question not specifically related to C++. Or, consult the nearest good
introductory textbook. ;-)
Do you think that answer would get you the job ?
There is a constructor (2 in fact) that the compiler created for you.
Why do somthing that the compiler does better ?
The whole point is, the questions are just the opening point for
discussion. For example, I can tell you're not very interested in the job !