I'm a C++ beginner. I have a class and when I try to compile it says it's missing 'main'.
What do I need to do to create an instance of this class and access its methods?
#include <string>
#include <iostream>
using namespace std;
class Account
{
string name;
double balance;
public:
Account(string n);
Account(string n, double initial_balance);
string get_name() const;
double get_balance() const;
void deposit(double amount);
void widthdraw(double amount);
};
edit:
Where do I put the main method?
I have tried putting it in a different file like the following
#include <Account>
int main(){
Account:: Account(string n) : name(n), balance(0){}
return 0 ;
}
but this gives an error saying there is not Account in the directory. I'm guessing this is because it's not compiled
edit:
Both files are in the same directory
account_main.cc
#include<string>
#include <iostream>
#include "Account.cc"
Account:: Account(string n) : name(n), balance(0){}
int main()
{
Account account("Account Name"); // A variable called "account"
account.deposit(100.00); // Calls the deposit() function on account
return 0 ;
}
Account.cc
#include<string>
#include <iostream>
using namespace std;
class Account
{
string name;
double balance;
public:
Account(string n);
Account(string n, double initial_balance);
string get_name() const;
double get_balance() const;
void deposit(double amount);
void widthdraw(double amount);
};