Calling a Class in Main function
Jul 21, 2016 at 5:43pm UTC
I made this code in main function.
1 2 3 4 5 6 7 8 9 10 11
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Name: Daniel\n" << "SSN: 9999 \n" << "DOT = 05/11/1990 \n" ;
return 0;
}
Then i created another source file (another class?) with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "stdafx.h"
using namespace std;
class ex_42 {
public :
string Letter_E()
{
return "*****\n*\n*\n*****\n*\n*\n*****\n" ;
}
};
Now when I am executing the project I want the class "Letter_E" to be called in my main function and do whats in it. I have tried different things but I cant figure it out on my own. How could I accomplish this?
Last edited on Jul 21, 2016 at 5:58pm UTC
Jul 21, 2016 at 6:02pm UTC
In main, you have to instantiate your class. Then you can call your Letter_E function.
1 2 3
ex_42 some_name;
some_name.Letter_e ();
Jul 21, 2016 at 6:15pm UTC
I tried this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "stdafx.h"
using namespace std;
class ex_42 {
public :
string Letter_E()
{ return "*****\n*\n*\n*****\n*\n*\n*****\n" ; }
};
int _tmain(int argc, _TCHAR* argv[])
{
ex_42 E_print;
cout << "Name: Daniel\n" << "SSN: 9999 \n" << "DOT = 05/11/1990 \n\n" << E_print.Letter_E();
return 0;
}
but i get "no operator "<<" matches theses operands
operand types are: std::ostream << std::string"
in the last << of the cout. I feel I'm really close.
Last edited on Jul 21, 2016 at 6:26pm UTC
Jul 21, 2016 at 6:29pm UTC
Lol just Had to include <string>.... silly me. But it worked!!!!!!! Ty so much @AbstractionAnon
Topic archived. No new replies allowed.