Pardon пример, но в этом случае:Извлечение значений объекта из массива?
#include <iostream>
#include <string>
using namespace std;
class A {
private:
string theName;
int theAge;
public:
A() : theName(""), theAge(0) { }
A(string name, int age) : theName(name), theAge(age) { }
};
class B {
private:
A theArray[1];
public:
void set(const A value) {theArray[0] = value; }
A get() const { return theArray[0]; }
};
int main()
{
A man("Bob", 25);
B manPlace;
manPlace.set(man);
cout << manPlace.get();
return 0;
}
Можно ли мне получить содержимое «человек» объект в основном, когда я называю manPlace.get()? Я намерен напечатать имя (Bob) и возраст (25), когда я вызываю manPlace.get(). Я хочу сохранить объект внутри массива в другом классе, и я могу получить содержимое указанного массива в главном.
'const A & temp = manPla ce.get(); '? –