首先,如果我在问题中使用了不正确的术语,我想道歉。我没有任何正式的编程培训。这是我能够做的最好的表达问题。如何访问超范围课程?
我的问题是这样的:
在下面的代码结构,Inventory类怎么能有项目载体的播放器类中未做矢量静态的完全访问权限?
- main.cpp中
#include <iostream>
#include <vector>
#include "World.hpp"
#include "Interface.hpp"
int main()
{
World objWorld;
Interface objInterface;
return 0;
}
- World.hpp
#pragma once
#include "Player.hpp"
class World
{
public:
Player objPlayer;
};
- Player.hpp
#pragma once
class Player
{
public:
std::vector<int> Items;
};
- Interface.hpp
#pragma once
#include "Inventory.hpp"
class Interface
{
public:
Inventory objInventory;
};
- Inventory.hpp
#pragma once
class Inventory
{
public:
// Needs to have complete access to Items, be able to see and modify the vector
};
类不会在运行时存在。对象确实存在。如果ypu给它们引用另一个对象,对象可以访问其他对象。 – 2017-08-02 11:33:15
如何将objWorld.objPlayer的引用传递给objInterface.objInventory? –
您的编辑完全改变了问题的焦点。请为此打开一个新问题。 (提示:它不会编译,因为'库存'不是默认构造的,实际上不能,只要它有一个引用成员)。 – ComicSansMS