What's the difference between a static data member and a regular data member?

Vector as a data member

  • This is a very short test program where I want to create objects which contain a vector as a data member. I can then add data to that vector from outside. Many of these objects would be created and I could then perform calculations using member functions. I am stuck right at the beginning. I am declaring a vector of double as a data member and tries to add to it but I am getting loads of error since the class does not recognize the vector as a member in the first place. here is my code. // Test to verify the use of a vector as a data member using namespace std; int g; class Vecttest // Class definition { Public: std::vector m_Price; // Data member }; int main() { Vecttest aaa; // add random values to the vector aaa.m_Price.push_back(1.0); aaa.m_Price.push_back(2.0); aaa.m_Price.push_back(41.0); aaa.m_Price.push_back(54.0); // Print back the vector data points cout > g; return 0; } Thanks for your help.

  • Answer:

    Hello Eric. The problem is that you are using Public with a capital 'P'. It should be lower case. Also, in your output loop, for(int i=0; i <4; i++) it is better to have for (size_t i = 0; i < aaa.m_Price.size(); i++) Keep experimenting.

Miningco.com Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.