Hi,
I am a newbie and just starting to learn C++.
I read that call by reference parameter is more efficient than a call by value parameter especially when the parameter passed was a class.
So I tried passing a class as a const call by reference parameter to a function.
When I did so, while compiling I got an error.
This error vanished when I removed the const parameter
Could you help me with this, I have given the details below:
Note - I use the command g++ on my mac to compile.
I have given below the definition of the function:
bool RatingAgency :: biggerBalance(const BankAccount& pBankAccount1, const BankAccount& pBankAccount2)
{
return(pBankAccount1.getAccountBalance() > pBankAccount2.getAccountBalance());
}
Note
- RatingAgency is the name of a class
- BankAccount is the name of a class, and it is being passed a parameter
- biggerBalance is the name of the function which belongs to the class RatingAgency
- getAccountBalance is a public function that belonged to the class BankAccount
Error
------
test.cpp:92: error: passing 'const BankAccount' as 'this' argument of 'double BankAccount::getAccountBalance()' discards qualifiers
test.cpp:92: error: passing 'const BankAccount' as 'this' argument of 'double BankAccount::getAccountBalance()' discards qualifiers
Line number 92 corresponds to the return statement in the function biggerBalance
Let me know if you need more information.
Thanks,
Muthu
I am a newbie and just starting to learn C++.
I read that call by reference parameter is more efficient than a call by value parameter especially when the parameter passed was a class.
So I tried passing a class as a const call by reference parameter to a function.
When I did so, while compiling I got an error.
This error vanished when I removed the const parameter
Could you help me with this, I have given the details below:
Note - I use the command g++ on my mac to compile.
I have given below the definition of the function:
bool RatingAgency :: biggerBalance(const BankAccount& pBankAccount1, const BankAccount& pBankAccount2)
{
return(pBankAccount1.getAccountBalance() > pBankAccount2.getAccountBalance());
}
Note
- RatingAgency is the name of a class
- BankAccount is the name of a class, and it is being passed a parameter
- biggerBalance is the name of the function which belongs to the class RatingAgency
- getAccountBalance is a public function that belonged to the class BankAccount
Error
------
test.cpp:92: error: passing 'const BankAccount' as 'this' argument of 'double BankAccount::getAccountBalance()' discards qualifiers
test.cpp:92: error: passing 'const BankAccount' as 'this' argument of 'double BankAccount::getAccountBalance()' discards qualifiers
Line number 92 corresponds to the return statement in the function biggerBalance
Let me know if you need more information.
Thanks,
Muthu