Answer» im a new programmer and I am testing my skills by programming simple little games. right now im using inline functions, i dont actually need them but i want practice with them.
when i compile the program it says " [linker error] undefined reference to `DrawingCards()' " and " ld returned 1 exit status " or itll say "'DrawingCards()' used but never DEFINED" and highlight the declaration in the header file.
Im not exactly sure what that means but i double checked everything and it SEEMS to look ok to me
It DECLARE it in the header file "int inline DrawingCards();"
Then define it in a separate source file "int DrawingCards() { int FirstHand = 0; ...... }
In the main loop i call it " PlayerHand += DrawingCards(); "
when it compiles the error comes up in the header file when i declare it: "int inline DrawingCards();"
from what i understand the error means that the compiler thinks im calling the function instead of declaring it. but im probably wrong. any suggestions to help me out?
----Also if i make the function a normal int function it compiles and runs fine. but i need it to be an inline function, i do have i loop in the function but it stops itself after 2 loops.
Or if you COULD just point me in the right direction or where i could obtain this information, i looked else where on information on inline functions and only found that the compiler decides if the function can be inlined and it may not inline them if the function is to big, and i doubt any of my functions are to big most are not even a page worth of lines. Write inline at the first declaration of the function in the header file and the whole code of the function:
inline init DrawingCards() { blablablabla }
Inline functions must not be more than 7 lines of code or so.
As a rule do not make inline functions that are too big and it depends on the compiler.change your Code: [Select]int DrawingCards() { int FirstHand = 0; ...... } to
Code: [Select]int inline DrawingCards() { int FirstHand = 0; ...... }
your declaration in the header file must match the implementation.
|