As we can see, I set default assignment. But the output is "Empty!"
You can try to run this code snippet to see the output.
Code:class Shape{ public: virtual void setType( const std::string& str = "abc") = 0; virtual void getType() const; private: std::string str_; }; void Shape::getType() const { if( str_.empty() ){ std::cout<<"Empty!"<<std::endl; }else{ std::cout << str_ << std::endl; } } void Shape::setType( const std::string& str) { str_ = str; } class Square:public Shape{ public: void setType( const std::string& str = "abc"){ str_=str; } private: std::string str_; }; int main(){ Shape * sp = new Square; sp->setType(); sp->getType(); return 0; }



LinkBack URL
About LinkBacks



CornedBee