Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Tier2, forward declaration of function, and scope problem

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 7th Mar 2018 13:16
Hello I've been searching the forum but can't find a solution. I have a single page C++ app, I have put a function at the bottom of the page and made a forward declaration function prototype at the top, but when I try to call the function from within app::Loop, it says it is not in scope. I have tried moving the function to the top but it changes nothing, I have tried moving the forward declaration inside app::Begin, still no luck, I have tried changing app::Loop to int main() and that wont make the function come in to scope either. So how do I create a function and a forward declaration of that function so that I can use it within app::Loop? I have read about it here: http://www.learncpp.com/cpp-tutorial/17-forward-declarations/ but that doesn't seem to compile when I try it with my app.
13/0
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 7th Mar 2018 15:05 Edited at: 7th Mar 2018 15:05
That is very odd. Function prototypes should "just work". Certainly moving the function to the top before it is referenced should fix the problem. The only way I could see that not fixing it is if the function itself is calling another function down below that has no prototype declared at the top.

Are you sure there is not another issue causing the problem? Maybe try making a very simple test program. It is strange terminology if the error actually says "not in scope". Seems like it would say something along the lines of unknown or not found.

I made a simple 3d shmup in AGK2 BASIC and C doing both versions simultaneously for a while. At work now but I can check that later and see how I structured it if nobody has replied by then.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 7th Mar 2018 17:37
GarBenjamin is right, it definitely sounds like it should work. Can you post the exact error you're getting and the code?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Mar 2018 18:08 Edited at: 7th Mar 2018 18:10
hmm its maybe different?

i just have

c++ in vs 2017 template.cpp




and it works, i can call Test(); also if this function is below the call
AGK (Steam) V2017.12.12 : Windows 10 Pro 64 Bit : NVIDIA (390.65) GeForce GTX 1050 Ti : Mac mini OS High Sierra (10.13)
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 8th Mar 2018 05:06 Edited at: 9th Mar 2018 03:46
Okay, here is a sample Base file... a template if you will... for an AppGameKit project.

This compiles and runs fine for me using Visual Studio. Of course you need to set up the references and external dependencies which should be done for you if you use the templates TGC provide.
The include file "Main.h" also came from that template.

The program itself is very simple it just creates 10 cubes on the screen. That is not the point of it though just to show this is what I do and works fine. So hopefully it will work for you.

This is "Main.cpp"
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 9th Mar 2018 03:36 Edited at: 9th Mar 2018 05:58
Just a note to say I updated that code above. Reason being I did a stupid thing of restructuring it here in the code block moving using namespace AGK; above #include "Main.h" and that of course breaks it because the namespace has not been defined yet!

Also I remembered you specifically said calling the function from inside app::Loop so I made a new function to display the framerate and call that from the main loop.

So now it works again!
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 9th Mar 2018 10:10
For crying out loud! I am really, really sorry guys :-( remove_game_server() is not the same as remove_game_host(). void test() forward declaration worked, and lead me on the right path to finding my spelling error. Again, I am really sorry, and thank you for all your help! You guys are solid!
13/0

Login to post a reply

Server time is: 2024-04-25 03:23:36
Your offset time is: 2024-04-25 03:23:36