半年以上ぶりのC++  
 

2002-12/4 (Wed)

 
 

はっきりいって憶えてないかとさえおもった。
でも書いていたらまぁ、結構憶えてるぢゃん。(笑

#include
#include

namespace peo {

class ISample
{
public :
virtual void Foo ( void ) const = 0 ;
} ;
}

namespace peo1 {
const int VERSION = 1 ;

class CSample : public peo::ISample
{
public :
void Foo ( void ) const ;

CSample() {
}
} ;

void CSample::Foo( void ) const {
std::cout << "Class namespace 1" << std::endl ;
}

template < typename T1 typename T2 >
struct Pair
{
typedef T1 first_type ;
typedef T2 second_type ;

T1 first ;
T2 second ;
Pair( const T1 &t1 const T2 &t2 ) : first( t1 ) second( t2 ) { }
} ;
}

namespace peo2 {
const int VERSION = 2 ;

// Class
class CSample : public peo::ISample
{
public :
void Foo ( void ) const ;

void Hoge( void ) const ;

CSample() {
}
} ;

void CSample::Foo( void ) const {
std::cout << "Class namespace 2" << std::endl ;
}

void CSample::Hoge( void ) const {

std::cout << "Class namespace 2" << std::endl ;

}
}

namespace peo3 {
const int VERSION = 3 ;

// Interface
class ISample
{
public :
virtual void Foo ( void ) const = 0 ;
} ;
}

// Global Class
class CSample : public peo3::ISample
{
public :
void Foo ( void ) const ;
void Hoge( void ) const ;

CSample() { }
} ;

void CSample::Foo( void ) const {
std::cout << "Global namespace (vir::peo3)" << std::endl ;
}

void CSample::Hoge( void ) const {
std::cout << "Global namescape (vir::peo3)" << std::endl ;
}

int main ( void )
{
using namespace peo ;
{
using namespace peo1 ;

{
using namespace std ;
cout << "VERSION INFORMATION" << " " << VERSION << endl ;
}

const peo1::CSample cs ;
cs.Foo() ;

Pair < int std::string > p( 3 "ほげ" ) ;
{
using namespace std ;
cout << "p :" << p.first << endl ;
cout << "p :" << p.second << endl ;
}

{
using namespace std ;
Pair< string string > p2( "ほげ" "ふが" ) ;
cout << "p2:" << p2.first << endl ;
cout << "p2:" << p2.second << endl ;
}

std::cout << std::endl ;

std::string strName = std::string() ;
strName.append( "すとりんぐ" ) ;

std::cout << strName << std::endl ;
}

std::cout << std::endl ;

{
using namespace peo2 ;
std::cout << "VERSION INFORMATION" << " " << VERSION << std::endl ;

const peo2::CSample cs ;

cs.Hoge() ;

}

std::cout << std::endl ;

{
using namespace peo3 ;

std::cout << "VERSION INFORMATION" << " " << VERSION << std::endl ;
const ::CSample cs ;

cs.Foo() ;
cs.Hoge() ;

peo1::Pair< std::string std::string > p3( "t-str1" "t-str2" ) ;
{
using namespace std ;
cout << "p3:" << p3.first << endl ;
cout << "p3:" << p3.second << endl ;
}
}
return 0 ;
}

という事で、ねぇ、この main() のmethodが
処理する表示結果わかりますよね♪(笑)