类和对象:
访问限定符:public 、protected、private;
对象实例化:从栈实例化
class tv{
public:
char name[20];
int type;
void changeVol();
void power();
};
int main(void){
TV tv;
TV tv[20];
return 0;
}
从堆实例化:
class tv{
public:
char name[20];
int type;
void changeVol();
void power();
};
int main(){
TC *p=new TV();
TV *q=new TV[20];
delete p;
delete []q;
return 0;
}
对象成员的访问:TV tv;
tv.type=0;
tv.changeVol();
return0;
堆:TV*p=new TV();
p->type=0;
p->changVol();
delete p;
p=NULL;
return;
///实例化一个类//
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Coordinate{
public:
int x;
int y;
void printX()
{
cout << x << endl;
}
void printY()
{
cout << y << endl;
}
};
int main(){
Coordinate *p = new Coordinate();
if (p == NULL){
return0;
}
p->x = 100;
p->y = 20;
p->printX();
p->printY();
delete p;
p = NULL;
system("pause");
return 0;
}