I have to make a .h file (with classes), link it with a .cpp file and g++ -c to create a .o file. Once I do that I have to link it with another .cpp file to get the results. And we have to do all this classes. It worked for me without classes but now I'm stuck. Right now I'm linking myint.h to myint.cpp to create a .o file (myint.o). Then I'm doing g++ -o main.cpp myint.o.
The errors I keep getting is:
main.cpp: In function 'int main()':
main.cpp:7:19: error: could not convert '5' from 'int' to 'MyInt'
main.cpp:8:23: error: could not convert '20' from 'int' to 'MyInt'
main.cpp:9:30: error: could not convert '32' from 'int' to 'MyInt'
I've tried everything I can think of.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//myint.h
#ifndef MYINT_H
#define MYINT_H
#include <iostream>
#include <string>
usingnamespace std;
class MyInt{
public:
int num;
};
MyInt myMax (MyInt x, MyInt y);
MyInt myMin (MyInt x, MyInt y);
MyInt myMiddle (MyInt x, MyInt y, MyInt z);
void prettyPrint (string word, int year);
#endif
I just saw it and while it's informative, I don't think it is what I need because my functions are not part of my class. The functions are separate but incorporate the class MyInt in them. Are you trying to say that my functions should be in the class?