I have a class that I'm writing that is split into its own .h and .cpp files.
In the .h file I've listed some function prototypes (declarations) listed below.
In the .cpp I have the definitions (so far) written as shown below.
However, if I try to build I get errors where it looks like the compiler thinks the return types for all my functions are int but they're declared as voids. My question is, do I have to state return types in the definitions as well as the declarations? That seems unnecessarily redundant to me. Is there something else I'm doing wrong?
Thanks for the quick reply! It's a little confusing to me that you don't have to state the parameter variable types again but you have to state the return type again.
Ah, that cleared up some other errors I was getting. Thanks again. Sorry, I had it in my head that once you prototyped with the variable types, you didn't have to state the types again.
you typically have to be explicit. This is partly because you can overload things, and partly because c++ is an explicit language.
I just copy my function headers and put a ; on them for the proto. It isnt necessary, but its easy enough.
does adding void in front and putting the type in, eg
void Wing::SetUnknown( *type* d_unknown ) {body}
clear your error?
remember that while it makes no sense here, it is mechanically ok to do this:
void Wing::SetUnknown( vector<double> d_unknown ) {body} //overloaded your method to take a completely different type, it would need a new proto as well, but see how the compiler can't assume too much?
Yes, it cleared out the remaining errors.
Thanks for your explanation. Yeah I can see how you'd need to state the types again for the possibility that you'd be overloading functions. Otherwise it wouldn't know which function definition went with which prototype.