c++-如何从一个类访问其他类结构
发布时间:2022-06-05 17:46:12 318
相关标签: # golang
我是一个初学者,正在努力学习编码。如果我的问题很愚蠢,请原谅。我有这两个类,我希望类存储可以访问来自struct Stock in class Toys的数据。我不知道该怎么做?
#include
#include
#include
class Toys {
public:
struct Stock
{
int x;
Stock(int value)
:x(value) {}
};
};
class Store {
public:
Toys myToy(int count) {
_count = count;
}
Toys* myStore;
//What do I need to do to bind a struct Stock from class Toy here?
private:
int _count;
};
int main()
{
Store myStore;
int x;
std::vector stocks;
std::cout << "Enter the availability for Water Gun.\n";
std::cin >> x;
for (int i = 0; i <= x; i++) {
stocks.push_back(i);
std::cout << stocks[i].x << std::endl;
}
//Later I want to pull vector stocks from class Store here.
return 0;
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报