Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Composition help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Mar 13, 2011 9:50 pm    Post subject: [C++] Composition help Reply with quote

This is a bank customer class, which has a savingsAccount (class/object) as one of its data members. Anyways..

Code:

#include <iostream>
#include <string>
using namespace std;


class SavingsAcc{

public:
   SavingsAcc(double argBal = 0, double argInt = 0);


   void setBalance(double);
   double getBalance(void);

   void setIntRate(double);
   double getIntRate(void);
   
   void monthlyInterest(void);

   
   
private:

   double balance;
   double intRate;
   
};

 



class Customer{

public:
   Customer(string argName = "", double argID = 00000, SavingsAcc arg);

   void setName(string);
   string getName(void);

   void setID(double);
   double getID(void);
   
private:
   string name;
   double ID;
   SavingsAcc savAcc;
   
};






int main(void){

   int n;
   cout << "How many bank customers would you like?";
   cin >> n;
   Customer *custArray = new Customer[n];
   //Gonna do other shit with this later once I can get it to compile -_-
   



   return(0);
}




// CUSTOMER CLASS IMPLEMENTATION

Customer::Customer(string argName, double argID, SavingsAcc arg){
   setName(argName);
   setID(argID);
    savAcc = arg;

}

void Customer::setName(string argName){
   name = argName;
}

string Customer::getName(void){
   return name;
}


void Customer::setID(double argID){
      ID = argID;
}

double Customer::getID(void){
   return ID;
}


// SAVINGS ACCOUNT CLASS IMPLEMENATION
SavingsAcc::SavingsAcc(double argBalance, double argIntRate){
   setBalance(argBalance);
   setIntRate(argIntRate);
}

void SavingsAcc::setBalance(double argBalance){
   if (argBalance < 0)
      argBalance = 0;
   balance = argBalance;
}

double SavingsAcc::getBalance(void){
   return balance;
}

void SavingsAcc::setIntRate(double argIntRate){
   if (argIntRate < 0)
      argIntRate = 1;
   intRate = argIntRate;
}

double SavingsAcc::getIntRate(void){
   return intRate;
}

void SavingsAcc::monthlyInterest(void){
   setBalance( getBalance()+(getBalance()*(getIntRate()/1200)));
   cout << getBalance();
}


I'm having this error:
Quote:
1>myfile.cpp(40): error C2548: 'Customer::Customer' : missing default parameter for parameter 3




How do I give it a default parameter beyond what I've already done..?
Kinda hit a wall as far as coming up with ideas to work around this..any help/tips would be greatly appreciated D:

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Mar 13, 2011 10:00 pm    Post subject: Reply with quote

You're setting default params for this:
Code:
class Customer{

public:
   Customer(string argName = "", double argID = 00000, SavingsAcc arg);


Anything after the first time you set a default param has to be defaulted as well. Meaning SavingsAcc must be defaulted to something too, such as null in your case.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Mar 13, 2011 10:25 pm    Post subject: Reply with quote

I sound dumber than I am asking this, but how do I accomplish that?

I dont know how to make the parameter have null values by default without sending it an object I make with null values.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Sun Mar 13, 2011 10:46 pm    Post subject: Reply with quote

Just set the constructor to:

Code:

Customer(string argName = "", double argID = 00000, SavingsAcc arg = NULL);

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Mar 13, 2011 11:13 pm    Post subject: Reply with quote

Wow, I feel pretty dumb now.
Thanks man, makes sense now. Thread over, basically. lol

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites