저는 class Birthday에 switch 문에 문제가 있습니다. 왜 클래스에 스위치를 넣을 수 없습니까? 난 해결하려고하지만, 실행 가능 코드를 나타내는 코드/statements이 아닌 임의의 클래스의 멤버 함수 (본체)을 배치해야하기 때문에, 난 비주얼 스튜디오 2,017switch 문을 클래스에 넣을 수없는 이유는 무엇입니까?
#include<string>
#include<iostream>
using namespace std;
class Birthday {
public:
Birthday(int d,int m,int y)
:day(d),month(m),year(y)
{
}
void printBirth() {
cout << month << " " << day << " " << year << endl;
}
private:
int day, month, year;
string month_name;
switch (month)
{
case 1:
month_name = "January"
break;
default:
month = "None";
break;
}
};
가능한 경우 : 코드를 언제 실행해야합니까? –