How to pass a pointer to an object to a function?

I'm writing a program for my class that has us creating a Fraction class and making some member functions and such for it. One of the requirements is that we need to have three other functions not including the ones in the class and one of these functions has to accept a pointer to a Fraction object and this function must use the pointer to update the object. This is what i have so far let me know if you need the whole code. I get this error when i try to compile the code.

Error 1 error LNK2001: unresolved external symbol "void __cdecl update_object(int,int,class Fraction)" (?update_object@@YAXHHVFraction@@@Z)

1
2
3
4
5
6
7
8
9
10
11
void update_object(int, int, Fraction); //function prototype
...
update_object(x,y,*a);  //call to function in int main()
...
void update_object (int xnum, int yden, Fraction *obj)
{
	obj->setNumerator(xnum);
	obj->setDenominator(yden);
	return;                  //function body
}
Your prototype doesn't match the definition. You are calling it like it takes a normal Fraction, but your definition is as if it takes a pointer.
Okay here is what i have figured out. and it works but does it do what i'm suppose to? Am i passing a pointer to my UpdateObject function?
1
2
3
4
5
6
7
8
void UpdateObject(int, int, Fraction*);
UpdateObject(x,y,a);
void UpdateObject (int xnum, int yden, Fraction* obj)
{
	obj->setNumerator(xnum);
	obj->setDenominator(yden);
	return;
}
Last edited on
...Yes, you are passing a pointer to your Fraction obj. As for what it does, only you can answer that as I don't know what it is "supposed" to do. It is modifying the actual object, if that's what you mean.
if you put your UpdateObject function before your main function (or before whatever function it is called in) you wouldnt need a prototype declaration in the first place.
Topic archived. No new replies allowed.