C++/CLIをつつく20-プロパティ2-書き込み専用プロパティ。使う場面が思い浮かばない。
public ref class Animal abstract
{
private:
Int32 m_age;
String^ m_name;
String^ m_password;
Animal(){}
public:
property Int32 Age {
Int32 get() { return this->m_age; }
void set( Int32 value ) {
if ( value > 0 ) m_age = value;
}
}
property String^ Name {
String^ get() { return this->m_name; }
}
//これが書き込み専用プロパティ
property String^ Password {
void set( String^ value ) { m_password = value; }
}
Animal ( String^ name, Int32 age ) {
this->m_name = name;
this->Age = age;
}
virtual void Talk( ) {
Console::WriteLine( "私は{0}。年は{1}だよ。",
this->Name, this->Age);
}
virtual void Move() abstract;
};
パスワードは特別な処理をすることが多いから、それを考慮して実装してみたピヨッ。 うーんでも苦しい・・・苦しいからこれで終わりピヨ。 もしかしたら使うべき局面があるかもしれないから一応覚えておいてね。 じゃあね。