I'm just starting to use objects. I cannot figure out how to pass data between objects. Here is what I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <sstream>
#include <stdexcept>
using namespace std;
class IntMoo{
private:
int number;
public:
IntMoo{
number=1;
}
Intmoo add(const IntMoo& n) const{
IntMoo whatever;
whatever.number = (n.number+number);
return whatever;}
};
int main () {
IntMoo random(1), name(1);
random.add(name);
return 0;}
|
Last edited on
Your parameter is "IntMod" not "IntMoo". Is that your problem?
There is some other problem.
I added in the rest of the program (well, this is not the program I have to turn in. It is a very simplified version).
Another question:
When I change data in an object then return to the main, does the data in the object stay changed?
How does my add function pass the value of n with "&" if n is a constant (my instructor requires the line "Intmoo add(const IntMoo& n) const"?
Last edited on