T
Tino
In the following code, can the indicated else statement ever be
reached? It seems to me that if either Val1 or Val2 are not passed to
the constructor, then there will be a compilation error. Am I
correct?
#include <iostream>
using std::cout;
using std::endl;
typedef enum { Val1, Val2 } Venum;
class A
{
int n;
public:
A( const Venum v )
{
if( v == Val1 )
n = 1;
else if( v == Val2 )
n = 2;
else // <---- Is this necessary
n = 0;
}
int get() const
{
return n;
}
};
int main()
{
A a1( Val1 ), a2( Val2 );
cout << "a1: " << a1.get() << ", a2: " << a2.get() << endl;
return 0;
}
reached? It seems to me that if either Val1 or Val2 are not passed to
the constructor, then there will be a compilation error. Am I
correct?
#include <iostream>
using std::cout;
using std::endl;
typedef enum { Val1, Val2 } Venum;
class A
{
int n;
public:
A( const Venum v )
{
if( v == Val1 )
n = 1;
else if( v == Val2 )
n = 2;
else // <---- Is this necessary
n = 0;
}
int get() const
{
return n;
}
};
int main()
{
A a1( Val1 ), a2( Val2 );
cout << "a1: " << a1.get() << ", a2: " << a2.get() << endl;
return 0;
}