小编Rob*_*son的帖子

Access array in header file C++

I have an object Room and each Room has an array of 4 references to other rooms

header file:

namespace test
{
    class Room
    {
    public:
        Room* references[4];
        void Connect(Room roomReference) const;
    }
}
Run Code Online (Sandbox Code Playgroud)

and in my cpp file, I am attempting to attach that reference by inserting the pointer of the room to a specific index in references. However, I get the following compiler error "Cannot assign to readonly type Room* const." But when I create a local variable …

c++ class constants member-functions pass-by-reference

1
推荐指数
1
解决办法
131
查看次数