C++访问类内部的vector <int>的值

tmi*_*hty 3 c++ windows class vector

我有以下课程:

class clsUnitArrayIndexToUnitID : public CBaseStructure
{
    private:
        std::vector<int> m_content;
        long m_size;
    protected:
        void ProcessTxtLine(string line);
    public:
        clsUnitArrayIndexToUnitID();
        std::vector<int>* Content;
        long Size();
};
Run Code Online (Sandbox Code Playgroud)

我想从类外部访问值,例如:

int iUnitID = m_MyClass.Content()[12];
Run Code Online (Sandbox Code Playgroud)

但是,C++告诉我,我需要使用点到函数类型.我不确定那意味着什么.

另外,如果有人在我的代码中看到任何缺陷,请告诉我.

eme*_*esx 7

将其更改为功能(const根据您的需要调整)

 public:
     const std::vector<int>& Content() const { return m_content; } 
Run Code Online (Sandbox Code Playgroud)

并按照您的描述使用,或以任一方式取消引用指针(不安全?):

m_MyClass.Content->at(12); 
(*m_MyClass.Content).at(12);
(*m_MyClass.Content)[12];
Run Code Online (Sandbox Code Playgroud)