Android Ndk 学习笔记(目录)
1 运算符重载
Position operator + (Position pos1 ,Position pos2){
int x = pos1.getX() + pos2.getX();
int y = pos1.getY() + pos2.getY();
return Position(x,y);
}
class Position{
private:
int x,y ;
public:
void setX(int x){
this->x = x ;
}
void setY(int Y){
this->y = y ;
}
int getX(){
return this->x;
}
int getY(){
return this->y;
}
public:
Position(){};
Position(int x,int y) :x(x),y(y){};
Position operator + (const Position & pos){
int x = this->getX() + pos.x;
int y = this->getY() + pos.y;
return Position(x,y);
}
void operator ++() {
this->x = this->x + 1;
this->y = this->y + 1;
}
void operator ++ (int) {
this->x = this->x + 1;
this->y = this->y + 1;
}
friend void operator << (ostream & _START, Position pos) {
_START << " " << pos.x << " ! " << pos.y << " " << endl;
}
friend istream & operator >> (istream & _START, Position & pos) {
_START >> pos.x >> pos.y;
return _START;
}
};
void function(){
Position pos1(100,200) ;
Position pos2(300,400) ;
Position pos3 = pos1 + pos2 ;
cout << pos3.getX() << "," << pos3.getY() << endl ;
Position result(1, 2);
result++;
++result;
cout << result;
Position res;
cin >> res;
cout << "你输入的是:" << res.getX() << endl;
cout << "你输入的是:" << res.getY() << endl;
}
class Person{
public:
char * name ;
int age ;
Person(char * name ,int age):name(name),age(age){
}
void show(){
}
};
class Worker : public Person{
public:
char * type ;
Worker(char * name , int age, char * type) : Person(name,age) , type(type) {}
void sayName(){
cout << name <<endl;
}
};
void functino02(){
Worker worker("张三",23,"钳工") ;
cout << worker.name <<endl;
}
class BaseClass1{
public:
int number = 0;
void show(){
}
};
class BaseClass2{
public:
int number = 0;
void show(){
}
};
class ZiClass : public BaseClass1,public BaseClass2{
public:
int number = 0;
void show(){
}
};
void functino03(){
ZiClass ziClass ;
ziClass.show();
ziClass.BaseClass1::show();
ziClass.BaseClass2::show();
cout << ziClass.number << endl;
cout << ziClass.BaseClass1::number << endl;
cout << ziClass.BaseClass2::number << endl;
}
class Object{
public:
int number;
void show() {
cout << "Object show run..." << endl;
}
};
class BaseActivity1 : virtual public Object {
};
class BaseActivity2 : virtual public Object {
};
class Zi : public BaseActivity1, public BaseActivity2 {
};
void functino04(){
Zi zi ;
Object ob1 ;
BaseActivity1 base1 ;
BaseActivity2 base2 ;
zi.number = 100 ;
ob1.number = 200 ;
base1.number = 300 ;
base2.number = 400 ;
cout << zi.number << endl;
cout << ob1.number << endl;
cout << base1.number << endl;
cout << base2.number << endl;
}
E:\C\Project\C++\cmake-build-debug\C__.exe
100
200
300
400
Process finished with exit code 0
|