A
aling
What's the rule of default argument of function in C++? I found that
the default argument of function could not necessary be a constant
value. Is it true? Previously I thought that the default argument of
function must be a constant value.
Here is my sample code, it's compiled successully in VC7.1.
#include<iostream>
class Base{
public :
virtual Base* copy( Base* ){
std::cout << "Base::copy\n" ;
return 0;
}
virtual std:stream& print( int , std:stream& os = std::cout ){
os << "Base:rint\n" ;
return os;
}
};
class Derived : public Base{
public :
Derived* copy( Base* ){
std::cout << "Derived::copy\n" ;
return 0;
}
std:stream& print( int , std:stream& os){
std::cout << "Derived:rint\n" ;
return os;
}
};
int main(){
Base* p = new Derived ;
p->copy( p ) ;
p->print( 1 ) ;
p->print( 1 , std::cout ) ;
std::cin.get() ;
}
the default argument of function could not necessary be a constant
value. Is it true? Previously I thought that the default argument of
function must be a constant value.
Here is my sample code, it's compiled successully in VC7.1.
#include<iostream>
class Base{
public :
virtual Base* copy( Base* ){
std::cout << "Base::copy\n" ;
return 0;
}
virtual std:stream& print( int , std:stream& os = std::cout ){
os << "Base:rint\n" ;
return os;
}
};
class Derived : public Base{
public :
Derived* copy( Base* ){
std::cout << "Derived::copy\n" ;
return 0;
}
std:stream& print( int , std:stream& os){
std::cout << "Derived:rint\n" ;
return os;
}
};
int main(){
Base* p = new Derived ;
p->copy( p ) ;
p->print( 1 ) ;
p->print( 1 , std::cout ) ;
std::cin.get() ;
}