Программы на C++. Форум разработчиков
-
Anonymous
Композиция на С++ не может получить ожидаемый результат
Сообщение
Anonymous »
У меня проблема с композицией, я не могу получить ожидаемый результат, помогите мне
Код: Выделить всё
#include
using namespace std;
class something{
int length;
public :
something(){length = 0;}
something(int l){length = l;}
void setLength(int l){length = l;}
int getLength(){return length;}
};
class person{
int age;
something obj_s;
public:
person(int i){age = i;}
void setS(int length)
{
something temp(length);
obj_s = temp;
}
something getS(){return obj_s; }
};
int main()
{
person p(20);
cout<
p.getS().setLength(20); //--------change at here---------
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/17506649/composition-in-c-cannot-get-the-expected-result[/url]
1737051563
Anonymous
У меня проблема с композицией, я не могу получить ожидаемый результат, помогите мне
[code]#include
using namespace std;
class something{
int length;
public :
something(){length = 0;}
something(int l){length = l;}
void setLength(int l){length = l;}
int getLength(){return length;}
};
class person{
int age;
something obj_s;
public:
person(int i){age = i;}
void setS(int length)
{
something temp(length);
obj_s = temp;
}
something getS(){return obj_s; }
};
int main()
{
person p(20);
cout<
p.getS().setLength(20); //--------change at here---------
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/17506649/composition-in-c-cannot-get-the-expected-result[/url]