1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> using namespace std; class Student { private : char name[10]; int age; int studentID; public : Student(char * _name, int _age, int _studentID) : age(_age), studentID(_studentID) { strcpy(name, _name); } void GetInfo() { cout << "name: " << name << endl; cout << "age: " << age << endl; cout << "studentID: " << studentID << endl; } }; int main() { Student * student[3]; char name[10]; int age, studentID; for (int i = 0; i < 3; i++) { cin >> name >> age >> studentID; student[i] = new Student(name, age, studentID); } for (int i = 0; i < 3; i++) { student[i]->GetInfo(); //질문1 왜 student[i].Getinfo(); 는 안되는지? } delete student[0]; delete student[1]; delete student[2]; // 질문2 왜 delete[] student; 하면 안되는지? return 0; } | cs |
38열 43열 질문 하나씩있습니다 형님들
행님들 주무시러 가셧나요 ㅜㅜ .과 ->가 같은역활을 한다고 알고있었는데 안되서 당황스럽네요 일단 ㅜㅜ
아래꺼는 각각이 다르게 선언되어서 그런거다 느낌은 알겠는데 1번질문은 잘모르겠어요
포인터라고 왜 인식되는거 같죠 student[1] 이런식이면 클래스로 인식해서 . 붙어도 상관없는거 아닌가요
->는 포인터에서부터 읽는거고 .은 객체에서부터 직접 접근할때 쓰는건가보네요 대충 혼자 결론내려야겠다
ㅇㅇ//되서->돼서 (되어 = 돼임) [리듬 맞춤법 봇♬]
ㅇㅇ//역활->역할 (역할 (役割)[명사] : 자기가 마땅히 하여야 할 맡은 바 직책이나 임무.) [리듬 맞춤법 봇♬]