switch calling a member function.

I'm uncomfortable with objects and usually just simplistically spell things out.
Question 1: in a switch how would I call a member function called this:
void BankingSystem::CreateAccount()
Question 2: Can I call this :
[code]
void PrintMenu()
{

std::cout << "\n(1) Add Account\n";
std::cout << "(2) Delete Account\n";
std::cout << "(3) Print Accounts\n";
std::cout << "(4) Deposit\n";
std::cout << "(5) Withdrawal\n";
std::cout << "(6) Exit\n";
std::cout << "\nEnter selection: ";

}
[code]
with this:
int main()
{



BankingSystem b;
int selection;

while (paycode <= 6)
{

std::cout << "\n*** Welcome to the Banking System ***\n";
std::cout << PrintMenu();


[code]
I'm just a little doofy with calling things and unsure of the syntax.
Thanks for reading and any input!
closed account (Dy7SLyTq)
yes you can because it evaluates the function and then gives the value to cout. i wouldnt use object that way because in c++ it means something else. its called a function usually
Thanks! So I"m going to use a switch for going between these 6 options. Because I'm an amateur I would generally have longwinded instruction in the body of each case for the six but for this will instead be using the member function spelled out in :
void BankingSystem::CreateAccount().
I know I'm going to do some sort of .CreateAccount() to call it but I"m at a loss on the phrasing.
Any input?
Thanks again!
That's just the first part but I think with a helpful example that I should be able to get the rest.
Last edited on
closed account (Dy7SLyTq)
sorry i misunderstood. if you make the member function static then you can call it by writing BankingSystem::CreateAccount();
Word up! I'll give it a shot! Thank you!
It's actually non-static. How would you go about calling that?
closed account (Dy7SLyTq)
static void CreateAccount(). define it in the class
closed account (Dy7SLyTq)
1
2
3
4
5
6
7
8
9
10
11
12
class MyClass
{
	public:
		MyClass() {}
		static string CreateAccount() { return "stuff"; };
};

int main()
{
	MyClass MyObject;
	cout<< MyClass::CreateAccount();
}
Last edited on
Thanks for your help. I'm trying to test things now for errors but it seems like it likes BankingSystem.CreateAccount(); alright.
Topic archived. No new replies allowed.