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
Related Q & A:
- What are some good "beginner level" data modeling/analytics approaches to kick start a data science/analytics team?Best solution by Quora
- How do I locate a Yahoo member?Best solution by Yahoo! Answers
- What is the difference between a team member and a sales associate?Best solution by Yahoo! Answers
- What are some phones for Verizon Wireless without a data plan or with a cheap data plan?Best solution by Yahoo! Answers
- Is Vector Marketing a scam?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.