# include <iostream>
using namespace std;
class Person {
public :
Person ( int age, char * name, string tel) : m_age ( age) , m_tel ( tel)
{
strcpy ( m_name, name) ;
}
void get_mem_value ( )
{
cout<< "m_age:" << m_age<< endl;
cout<< "m_name:" << m_name<< endl;
cout<< "m_tel:" << m_tel. c_str ( ) << endl;
}
private :
int m_age;
char m_name[ 20 ] ;
string m_tel;
} ;
void test1 ( )
{
Person per ( 20 , "zhangsan" , "13296639109" ) ;
per. get_mem_value ( ) ;
}
int main ( )
{
test1 ( ) ;
return 0 ;
}
# include <iostream>
using namespace std;
class Animal
{
public :
Animal ( int weight, int height) : m_weight ( weight) , m_height ( height) { }
virtual void get_data ( )
{
cout<< "m_weight" << m_weight<< ", m_height" << m_height<< endl;
}
private :
int m_weight;
int m_height;
} ;
class Dog
{
public :
Dog ( int type, int weight, int height) : m_type ( type) , m_animal ( weight, height) { }
void get_data ( )
{
cout<< "m_type:" << m_type<< endl;
m_animal. get_data ( ) ;
}
private :
int m_type;
Animal m_animal;
} ;
class Cat : public Animal
{
public :
Cat ( int type, int weight, int height) : m_type ( type) , Animal ( weight, height) { }
private :
int m_type;
} ;
int main ( )
{
Cat ct ( 10 , 20 , 30 ) ;
Dog dg ( 40 , 50 , 60 ) ;
Animal * mal = & ct;
mal-> get_data ( ) ;
dg. get_data ( ) ;
return 0 ;
} ;
class ConstExample {
const int value;
public :
ConstExample ( int v) : value ( v) { }
} ;
class RefExample {
int & ref;
public :
RefExample ( int & r) : ref ( r) { }
} ;
class OrderExample {
int a;
int b;
public :
OrderExample ( int x) : b ( x) , a ( b + 1 ) { }
OrderExample ( int x) : a ( x + 1 ) , b ( x) { }
} ;
class Example {
std:: string name;
int value;
public :
Example ( const std:: string& n, int v) : name ( n) , value ( v) { }
Example ( const std:: string& n, int v) {
name = n;
value = v;
}
} ;
class ModernClass {
int x = 10 ;
std:: string s = "default" ;
const double pi = 3.14159 ;
public :
ModernClass ( ) = default ;
ModernClass ( int val) : x ( val) { }
} ;
class Complex {
int a, b, c;
public :
Complex ( ) : Complex ( 0 , 0 , 0 ) { }
Complex ( int x) : Complex ( x, 0 , 0 ) { }
Complex ( int x, int y, int z) : a ( x) , b ( y) , c ( z) {
}
} ;