I'm trying to practice basic constructor problems and ran into this issue. It should display "unknown" when no string is passed. Here is my code:
#include <iostream>
#include<string>
class Student{
private:
std::string name{};
public:
Student() : name{"unknown"}
{};
Student(std::string s){
name = s;
}
void get_name(){
std::cout<<name;
}
};
int main(){
Student student;
std::cout<<"Default name is: "<<student.get_name<<std::endl;
Student custom_student("adam");
std::cout<<"Custom name is: "<<custom_student.get_name<<std::endl;
return 0;
}