C++学習ノート(対象向け)
1921 ワード
C++はオブジェクトに面する言語です
クラス定義&オブジェクト
C++の継承、マルチステート、抽象
クラス定義&オブジェクト
class A{
public:
int a;
static int num;// ,
void setB(int _b);
int getB(void);
A();//
~A();//
A(const A &obj);// ( )
friend void print( int x );// , , Java ,
double Volume(){
return length * breadth * height;
}
int compare(Box box){
return this->Volume() > box.Volume();//this
}
static int getNum(){// 。。。
return num;
}
protected:
double c;//
private:
int b;// , Java get set
int *ptr;
};// java
int A::num = 10086;// A num
A::A(void){
cout << " " << endl;
}
A::~A(void){
cout << " " << endl;
}
Line::Line(const Line &obj)
{
cout << " ptr " << endl;
ptr = new int;// ... new
*ptr = *obj.ptr; //
}
int A::getB(void){
return b;
}
void A::setB(int _b){
b = _b;
}
void print(int x){
cout << "this is :" << x <
C++の継承、マルチステート、抽象
# include
using namespace std;
class Color{
public:
int a;
virtual int needBeImpl() = 0; // ,Java
};
class Name{
public:
int b;
void setName(){
}
};
class Sth : public Color,public Name{// : , (java ) extends , private。
public:
int getColor(){
return 0;
}
virtual void setName(){
// virtual
}
};
int main(void){
return 0;
}