473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Assigning from a vector of objects to a variable

I am storing previously entered values of a,b,c in a vector as you can see below. Later the user has the option to use one the objects from the vector, and assigns the value to the variables, which therefore are entered using the old values. But the problem is the object assigned are meaningless numbers(i.e. 32252355). How can I get the value of one of the old 'a'(eg. a of that particular slot) and assigned to the new 'a'?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. template <class A, typename B>
  5. class AClass
  6. {
  7. private:
  8.   vector<A> aVector;
  9. public:  
  10.   void AFunc(A t1)
  11.   {     aVector.push_back(t1);
  12.   }
  13.    B get_aV(B i){
  14.          return aVector[i].get_a();
  15.   }
  16. };
  17.  
  18. class BClass {
  19. private:
  20.     int a,b,c;
  21. public:
  22.     BClass (int a1, int b1, int c1) : a(a1), b(b1), c(c1) {}
  23.  
  24. int get_a() {
  25.     return a;
  26. }
  27. };
  28. int main() {
  29.    int a,b,c;
  30. //ordinarily a,b,c are entered from the keyboard(excluded)
  31.  
  32.    AClass<BClass,int> x;
  33. //later the user has the option of using the old values entered so
  34.    AClass.AFunc(BClass (a,b,c));
  35.    a = AClass.get_aV(1);
  36. //same for b and c respectively
  37.    return 0;
  38. }
  39.  
If an object is made up of a,b,c as seen from the constructor, how can I get only the a of that object?
Mar 6 '08 #1
1 1354
jabbah
63
aVector.push_back() gets executed only once, so there is no
aVector[1] but only an aVector[0].
Mar 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
0
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated...
12
by: ypjofficial | last post by:
Hello All, I need to return a vector from a function.The vector is of int and it can contain as many as 1000 elements.Earlier I was doing //function definition vector<intretIntVector() {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.