windows - C++ accessing a value of vector<int> that is inside class -


this question has answer here:

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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -