클래스 포인터
977 단어 포인터
#include<iostream>
using namespace std;
class Student
{
public :
void set();
void show();
private:
int num;
int data;
};
void Student::set()
{
cout<<"please input one student num:";
cin>>num;
cout<<"please input one student data:";
cin>>data;
}
void Student::show()
{
cout<<"the student num:"<<num<<"and data:"<<data<<endl;
}
int main()
{
Student std[5];
Student *p;
p=&std[0];
int i=0;
while(i<5)
{
//(*p).set();
(*(p+i)).set();
cout<<"ok>>end:"<<++i<<endl;
}
(*p).show();
(*(p+2)).show();
(*(p+4)).show();
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Go 언어】interface 의 포인터로부터 메소드 호출할 수 없는 것은 왜?간결하게 말하면 「interface 를 가리키는 포인터는 interface 를 실장한 구조체의 포인터의 포인터가 되기 때문」입니다. 이것만으로는 잘 모르기 때문에 자세히 살펴 보겠습니다. interface의 Mamm...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.