windows - C++ accessing a value of vector<int> that is inside class -
this question has answer here:
- accessing vector in class 3 answers
i have following class:
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(); };
i access values outside class, example this:
int iunitid = m_myclass.content()[12];
however, c++ tells me need use point-to function type. not sure exactely means.
also, if sees flaw in code, please tell me.
change function (adjust const
needs)
public: const std::vector<int>& content() const { return m_content; }
and use described, or dereference pointer (unsafe?) in either way:
m_myclass.content->at(12); (*m_myclass.content).at(12); (*m_myclass.content)[12];
Comments
Post a Comment