my dynamic pointer wont pass values

This is a discussion on my dynamic pointer wont pass values within the C++ Programming forums, part of the General Programming Boards category; Code: #include "accounts.h" class Bank:Account{ sav_acct *Ps; chk_acct *Pc; time_acct *Pt; char name[20]; char addy[50]; public: Bank(int x, int y, ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    my dynamic pointer wont pass values

    Code:
    #include "accounts.h"
    
    class Bank:Account{
    	sav_acct *Ps;
    	chk_acct *Pc;
    	time_acct *Pt;
    	char name[20];
    	char addy[50];
    public:
    	Bank(int x, int y, int z);{
    		Ps = new sav_acct[x];
    		Pc = new chk_acct[y];
    		Pt = new time_acct[z];
    }
    now, int's x y and z all make it here, but i cant make them go to the arrays,

    for example when i do Bank B1(200, 400, 200),
    it doesnt pass 200 to the sav_account[]
    **note** sav_ acct and all them are defined in accounts.h

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Code:
    #include "accounts.h"
    
    class Bank:Account{
    sav_acct *Ps;
    chk_acct *Pc;
    time_acct *Pt;
    char name[20];
    char addy[50];
    public:
    Bank(int x, int y, int z);{
    Ps = new sav_acct[x];
    Pc = new chk_acct[y];
    Pt = new time_acct[z];
    }
    to...

    Code:
    #include "accounts.h"
    
    class Bank:Account{
    sav_acct *Ps;
    chk_acct *Pc;
    time_acct *Pt;
    char name[20];
    char addy[50];
    public:
    Bank(int x, int y, int z)
    {
    Ps = new sav_acct[x];
    Pc = new chk_acct[y];
    Pt = new time_acct[z];
    }
    };
    Also, when you say "it doesnt pass 200 to the sav_account[]" do you mean, it doesn't make sav_account an array of 200 elements? Or something else?

    The code I posted should work... although it's a bit dangerous (the memory isn't deleted, x,y,z aren't checked to be valid sizes, etc).
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    Re: ~

    Originally posted by rmullen3
    Code:
    #include "accounts.h"
    
    class Bank:Account{
    sav_acct *Ps;
    chk_acct *Pc;
    time_acct *Pt;
    char name[20];
    char addy[50];
    public:
    Bank(int x, int y, int z);{
    Ps = new sav_acct[x];
    Pc = new chk_acct[y];
    Pt = new time_acct[z];
    }
    to...

    Code:
    #include "accounts.h"
    
    class Bank:Account{
    sav_acct *Ps;
    chk_acct *Pc;
    time_acct *Pt;
    char name[20];
    char addy[50];
    public:
    Bank(int x, int y, int z)
    {
    Ps = new sav_acct[x];
    Pc = new chk_acct[y];
    Pt = new time_acct[z];
    }
    };
    Also, when you say "it doesnt pass 200 to the sav_account[]" do you mean, it doesn't make sav_account an array of 200 elements? Or something else?
    yeah thats what i mean... and i changed it, ran the debugger till after i ran the constructor in my main, and it still didnt make the 200 :-(

  4. #4
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Well, does it work in the program... or is it just the debugger that says it hasn't been allocated
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  3. How to pass enum values
    By Bargi in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2007, 03:55 AM
  4. HowTo increase 1 value to the pointer and pass by ref?
    By Mathsniper in forum C Programming
    Replies: 10
    Last Post: 10-29-2005, 06:21 PM
  5. void pointer and dynamic memory help
    By hans in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2002, 09:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21