// C++
#include <stdio.h>
#include <string.h>
#define PRINT_CHAR(chr) printf("\t"#chr"=%c\n",chr)
const unsigned CORRESPOND[ ] = { 0 ,2 ,3 ,1 } ; // 對應順序 A->第0個字元, B->第2個字元 , ...
class TEST
{
private :
char chrData[ 4 ] ;
public :
char & chrA, & chrB, & chrC, & chrD;
TEST( const char * data) : chrA( chrData[ CORRESPOND[ 0 ] ] ) , chrB( chrData[ CORRESPOND[ 1 ] ] ) , chrC( chrData[ CORRESPOND[ 2 ] ] ) , chrD( chrData[ CORRESPOND[ 3 ] ] )
{
memcpy ( chrData, data, 4 * sizeof ( char ) ) ;
}
TEST( const TEST & cpy) : TEST( cpy.chrData )
{
}
public :
void ShowABCD( ) const
{
PRINT_CHAR( chrA) ;
PRINT_CHAR( chrB) ;
PRINT_CHAR( chrC) ;
PRINT_CHAR( chrD) ;
}
void ShowDataArray( ) const
{
PRINT_CHAR( chrData[ 0 ] ) ;
PRINT_CHAR( chrData[ 1 ] ) ;
PRINT_CHAR( chrData[ 2 ] ) ;
PRINT_CHAR( chrData[ 3 ] ) ;
}
} ;
int main( )
{
TEST t1( "0123" ) ;
printf ( "\n The Data of t1:\n " ) ;
t1.ShowABCD ( ) ;
t1.ShowDataArray ( ) ;
t1.chrB = 'B' ;
TEST t2( t1) ;
printf ( "\n The Data of t2:\n " ) ;
t2.ShowABCD ( ) ;
t2.ShowDataArray ( ) ;
return 0 ;
}
Ly8gQysrCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8c3RyaW5nLmg+CiNkZWZpbmUgUFJJTlRfQ0hBUihjaHIpIHByaW50ZigiXHQiI2NociI9JWNcbiIsY2hyKQpjb25zdCB1bnNpZ25lZCBDT1JSRVNQT05EW10gPSB7MCwyLDMsMX07CS8vIOWwjeaHiemghuW6jyBBLT7nrKww5YCL5a2X5YWDLCBCLT7nrKwy5YCL5a2X5YWDICwgLi4uCmNsYXNzIFRFU1QKewpwcml2YXRlOgoJY2hhciBjaHJEYXRhWzR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