Post: [Help C++] Increment a class vector
05-06-2016, 01:38 AM #1
Broko
Keeper
(adsbygoogle = window.adsbygoogle || []).push({}); What I'm trying to do is to have an infinite number amount of vectors from the Bank class. I've tried using push_back but it doesn't seem to work for me.

Yes I know I may not need some of the loops and it can be formatted better.

I believe that's all that is needed for you guys to help me.

    
using namespace std;

int main()
{
bool loop1 = true;
bool loop2 = true;
bool loop3 = true;
bool loop4 = true;
int i = 0;
int clientInt;

while (loop1)
{
vector<Bank> clients(2);

while (loop2)
{
while (loop3)
{
clients[i].set_account(clients);

if (clients[i].get_account_setup() == false)
break;

while (loop4)
{
clients[i].main_menu(clients, i);

if (clients[i].get_mm_response() == 4)
loop4 = false; i++;
}
//cout << i << endl; // for debugging purposes

loop4 = true;
}

loop2 = false;
}

cout << endl << endl;
system("pause");
return 0;
}
}
05-06-2016, 07:02 AM #2
Toxic
former staff
Originally posted by Broko View Post
What I'm trying to do is to have an infinite number amount of vectors from the Bank class. I've tried using push_back but it doesn't seem to work for me.

Yes I know I may not need some of the loops and it can be formatted better.

I believe that's all that is needed for you guys to help me.

    
using namespace std;

int main()
{
bool loop1 = true;
bool loop2 = true;
bool loop3 = true;
bool loop4 = true;
int i = 0;
int clientInt;

while (loop1)
{
vector<Bank> clients(2);

while (loop2)
{
while (loop3)
{
clients[i].set_account(clients);

if (clients[i].get_account_setup() == false)
break;

while (loop4)
{
clients[i].main_menu(clients, i);

if (clients[i].get_mm_response() == 4)
loop4 = false; i++;
}
//cout << i << endl; // for debugging purposes

loop4 = true;
}

loop2 = false;
}

cout << endl << endl;
system("pause");
return 0;
}
}


Moved to programming inquires for time being
05-07-2016, 08:45 AM #3
Winter
Purple God
Originally posted by Broko View Post
What I'm trying to do is to have an infinite number amount of vectors from the Bank class. I've tried using push_back but it doesn't seem to work for me.

Yes I know I may not need some of the loops and it can be formatted better.

I believe that's all that is needed for you guys to help me.

    
using namespace std;

int main()
{
bool loop1 = true;
bool loop2 = true;
bool loop3 = true;
bool loop4 = true;
int i = 0;
int clientInt;

while (loop1)
{
vector<Bank> clients(2);

while (loop2)
{
while (loop3)
{
clients[i].set_account(clients);

if (clients[i].get_account_setup() == false)
break;

while (loop4)
{
clients[i].main_menu(clients, i);

if (clients[i].get_mm_response() == 4)
loop4 = false; i++;
}
//cout << i << endl; // for debugging purposes

loop4 = true;
}

loop2 = false;
}

cout << endl << endl;
system("pause");
return 0;
}
}


A) A lot of code is missing and we're unable to assist.
B) A vector can only be as large as the memory allows, therefore one declaration of a vector is infinite already since the class moves the values around the memory.

The following user thanked Winter for this useful post:

Specter
05-07-2016, 10:08 PM #4
Specter
Pro Memer
I'm not really sure what that code is, like why you have infinite loops inside infinite loops, there's probably a much better way to do this, but even you yourself stated that.

In regards to your question it's unclear, what do you mean by an infinite number of vectors of a bank class? Do you mean a lot of bank objects allowed in one vector? That's the purpose of vectors, is they grow efficiently if needed, but it can only grow as large as memory permits.
05-10-2016, 07:32 AM #5
Broko
Keeper
Originally posted by Winter View Post
A) A lot of code is missing and we're unable to assist.
B) A vector can only be as large as the memory allows, therefore one declaration of a vector is infinite already since the class moves the values around the memory.


Sorry about that thanks for the reply though. I figured out the problem.

It turned out that I needed to make an object for the Bank class and then put that object in the parameter of clients.pus
05-10-2016, 07:34 AM #6
Broko
Keeper
Originally posted by F View Post
I'm not really sure what that code is, like why you have infinite loops inside infinite loops, there's probably a much better way to do this, but even you yourself stated that.

In regards to your question it's unclear, what do you mean by an infinite number of vectors of a bank class? Do you mean a lot of bank objects allowed in one vector? That's the purpose of vectors, is they grow efficiently if needed, but it can only grow as large as memory permits.


Originally posted by Winter View Post
A) A lot of code is missing and we're unable to assist.
B) A vector can only be as large as the memory allows, therefore one declaration of a vector is infinite already since the class moves the values around the memory.


Sorry about that and thanks for the reply though. I figured out the problem.

It turned out that I needed to make an object for the Bank class and then put that object in the parameter of clients.push_back()

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo