Class and Object Calling Problem

Hey I have a little problem hope someone can help me solve it.

- I have a class it’s own source file.
- I have created an object at the end of the class:
1
2
3
4
5
class ThePlayer
{ public:
void SomeFunction();

}MyPlayerObject;




- Now in main source file. I am trying to call my class function called SomeFunction();
- So when I have this code: MyPlayerObject.SomeFunction();
- I get an error. I thought it would work since I already created an instance already in the class source file.

Can anyone tell me what is wrong and how to fix? Also I think the error was called LNK multiply or something cannot remember.
Last edited on
You have several potential issues.

Firstly, SomeFunction() is private (by default for a class) so can't be called from outside the class. You need a public: access specifier.

Secondly, how is your class made known to main()? Is it by linking or by #include'ing? Either way, main() will need to see a prototype: ideally in a header file.

Please always give the error message. Also, it helps if you provide "the minimum compileable code that reproduces the problem".
Last edited on
My mistake I forgot to put the include and public when posting.
But everything in my code is all public and I have included all the linked source files.

Anyone know the answer to my question?
Last edited on
I think the error was called LNK multiply or something cannot remember.

So go compile your code and post the error message
Topic archived. No new replies allowed.