4
は、オブジェクトにアクセスしている間、私は問題に直面しているやあ、私のプログラムで
は2クラスクラスAとB
クラスBがプライベートとしてkeptsメンバー変数名を、持っているがあります
。 gettes/setter関数はこの変数にアクセスします(変数はprivateです)。
クラスAには、メンバ変数Bクラス(プライベート)のオブジェクトがあります。クラスの外にこのオブジェクトを取得するためにゲッタを使用しています。
今、クラスaのオブジェクトを使用してオブジェクトbの名前を設定します。 次のコードを作成しましたが、動作しませんでした。
私はこれを解決するために手伝ってください。
// GetObject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
class B
{
int name;
public:
int getname()
{
return name;
}
void SetName(int i)
{
name = i;
}
};
class A
{
private:
B b;
public:
B GetB()
{
return b;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int ii = 10;
A a;
a.GetB().SetName(ii);
std::cout<<" Value :"<<a.GetB().getname();
getchar();
return 0;
}
yaa .... thats良いアイデア。 私はちょうど今試みました。仕事は非常に感謝します。 –
@Aneeshは、喜んで助けてください。 –