![]() |
|
No member Function Declared |
joshua.tilson
Member #7,552
July 2006
![]() |
Hello every one, I am new to these forums, and am hoping some one can give me some quick advice. I have recently started programing C++ some i am just a noob, but i have a good feel for a lot of the basics. Recently i started wroking with allegro, testing out some random function, and on others advice started doing the PONG game just to get the hang of game logic. I am having a heck of a time when i compile, It is telling me that Certain member functions are not declared within the class, allthough they are declared exactly the same as the other member fucntions in the same class. Mainly it is my pad() member function that is supposed to move the players paddle.
Thanks you guys for taking the time to look at this mess i have made! |
Steve++
Member #1,816
January 2002
|
Try this (may still have some errors):
|
joshua.tilson
Member #7,552
July 2006
![]() |
Ok i will change that, also I have put the DrawPaddle and pad member functions together, this seems to work for me... allthough it seems that any time i try to define more than one member function for a class it gives me the no member function declared.... Ghar! |
Tomoso
Member #3,128
January 2003
![]() |
Instead of accessing and changing your Class Member Variables directly. Try using Accessor Functions. This makes sure your variables remain unchanged unless you specifically call the correct function within the class. It also allows you to carry out error checking. For Example:
Err I hope that helps. I got distracted when writing this and forgot the point I was trying to make. Gtg now >.< Lazy Noob - Blog |
Steve++
Member #1,816
January 2002
|
First post edited. Have a look. |
joshua.tilson
Member #7,552
July 2006
![]() |
thank you for the help guys! thank you |
Steve++
Member #1,816
January 2002
|
That is not the case. It sounds like you're misinterpreting compiler errors. Please copy and paste you compiler errors here so we can tell you what they really mean. I'm going to sleep now, so I'll let someone else do the honours. |
joshua.tilson
Member #7,552
July 2006
![]() |
Ok here is my compiler error: 69 G:\Dev-Cpp\pongclasses.cpp no `int Player::getPos()' member function declared in class `Player' this is just an eample, in my pongclasses.h I added int getPos(); not sure exactly whats goign on.. |
Steve++
Member #1,816
January 2002
|
pongclasses.cpp is only 64 lines, so that isn't really helpful to me. Can you please post whatever code you have now and the error messages that the compiler is giving, so we can help you figure them out? |
joshua.tilson
Member #7,552
July 2006
![]() |
Steve++ well here is the code i am using now. and I took the hint on the style of how to write it from http://www.cppgameprogramming.com/cgi/nav.cgi?page=index here is my new code
Now i did use his examples of how he did it, but i wrote my own code... thanks guys |
Steve++
Member #1,816
January 2002
|
Instead of using a single direction value, use x and y direction values. Better still, use deltas. Call them dx and dy. They will represent the number of pixels to move in the x and y directions per frame. Then you can just switch the sign of dx when the x extremities are reached and the same for dy and y. The following code does this, but also adds something a little more complex. It allows for increments greater than one. For example, if dx = 8, then x is travelling to the right, eight pixels per frame. In this same example, if x is six pixels away from a wall, it will move six pixels to the right, then two to the left. It has the same effect as looping single increments eight times, but without the inefficiency. Observe:
Formulae such as x = 2 * MAX_BALL_X - dx - x may seem strange. This one, for example is derived from x = MAX_BALL_X - (dx - (MAX_BALL_X - x)), which may be more descriptive to you. That takes care of x. To calculate y, you will need a similar structure as the code above, but of course with the addition of collision testing with the player object (assuming the player(s) move(s) horizontally). Hope this helps. |
joshua.tilson
Member #7,552
July 2006
![]() |
Hey Steve! Aweosme, thanks fo the help. Havent got much into Matha nd programming yet, finding out im goignt o have to study up, know any good tutorials or reading on programming math? Umm I did the X and did one very similar to it for Y, i have not got the colision deticiton goiung yet, still puzzling on that one. I have run into something wierd with this code though, when the ball hits the wall either X-0 or Y-0 it just runns along the top or side of the screen.. trying to find what causes that as well. |
Steve++
Member #1,816
January 2002
|
Oops... try this:
Stupid error |
joshua.tilson
Member #7,552
July 2006
![]() |
In general "they" say to trust your gut instinct, or in the case of school your first instinvct on the answer is usually right. I had looked at the >= and <= and thought about changing that.. Thank you so much for the help! Once i get this part down im going to try to add soem GUI to allow the player to choose wheter to start a 2 player, 1 player vs compuer or quit.. I have been looking into some GUIs for allegro.. I have heard that the built in gui is awfull, is that true? and what of ones like Guichan, or the unuglification gui? Oh well imight just try the built in one, doesnt need to be pretty this is all for practice in game programming logic and theory. thanks again for the help! P.S I got it working with the colision detection and everything, man was that part easy I'm dumb!! check it out: if (dy < 0 && ballX >= pX1 && ballX <= pX2 && ballY == 25) { dy = -dy;} if (dy > 0 && ballX >= cX1 && ballX <= cX2 && ballY == 455) { dy = -dy;}
I added that right above yourr dx and dy code! I nominate you for noob helper of the year! |
Kauhiz
Member #4,798
July 2004
|
If you're just going to have a menu where the player can choose 1 or 2 player game and stuff like that, you probably won't need to use a gui at all. Just code some buttons, they'll look nicer, and will probably be easier than learning a gui lib, since you won't need most of it. --- |
Steve++
Member #1,816
January 2002
|
The Allegro GUI is a 'perfect' system once you understand it. By perfect, I mean that it does exactly what it's supposed to do and nothing more, and it is quite compact. It is perfect for a C programmer, but a bit ugly if you're used to an object oriented GUI interface. Luckily there are some helper functions that show various sorts of dialogue boxes. I'd look into that first, because it will most likely save you having to use a gui API (be it Allegro's or some other add-on). Good to hear you got it all working. I've never actually written pong myself, but I've done plenty of balls-bouncing-off-walls stuff. Quote: I nominate you for noob helper of the year! Sigged |
joshua.tilson
Member #7,552
July 2006
![]() |
Well hey pong seemed long the logical place to start, I mean start at the beginning and work up right? Next i will writer Zork I'm dumb! yeah right. well Im off for some good old fashioned learnin! |
Steve++
Member #1,816
January 2002
|
Yeah, pong is a good place to start, but at the time I was 13 and I thought it was beneath me. |
joshua.tilson
Member #7,552
July 2006
![]() |
Well lucky for me i waited about 12 years longer than you to start coding.. Oh wait not lucky me damnit! Why couldn't i do this earlier? Wish me luck on the GUI, i will post here periodically with updates on whats goign on with this rinky dink project of mine! thanks again! Hey on a side note, I am looking at the Allegro GUI tutorial at http://agdn.netfirms.com/main/gui/dialogs.html and i have taken their color builder code to try and see how things work, only the call to update_color doesnt work, is that depreciated or what? wha is used now instead of that? oh well least with that out it works other than changing the olor, trying to figure this bit out now! |
jakerohs
Member #485
June 2000
![]() |
Slightly offtopic, but I noticed that you <included.h> your own files, as opposed to "including.h" them. Can anyone explain the difference to me? I've always used < > for libraries, and " " for my own files. |
Steve++
Member #1,816
January 2002
|
Josh, that tutorial is quite old, so there may be some things in there that have been deprecated. Jake, the difference is that "including" them searches in the same directory as the file that's "including" them, whereas <including> them looks in the compiler's include directory. |
LennyLen
Member #5,313
December 2004
![]() |
joshua.tilson, I have attached the code for a simple program that creates a skeleton class with more than one member function and then uses it. Try compiling it to see if you get the same error (it compiled perfectly for me). I'm guessing you may have the same problem since when I tested your code, while it threw up a ton of errors, none of them was the error you got. Quote: And it seems that if i post, and then have an update.. i cannot rpost unless osme one else has posted after me? wierd... ML designed the forum this way deliberately. If you've ever come across forums where people post ten posts in a row, each updating the last one, you'll appreciate why. If you want to add new material to a post, edit it and enclose the new material in [update][/update] or [edit][/edit] (or something similar). These aren't real forum tags, but they let others know that you've added new material. Jake Rohs said: Slightly offtopic, but I noticed that you <included.h> your own files, as opposed to "including.h" them. Can anyone explain the difference to me? The compiler determines where to look for the file being included by checking if it's name is enclosed in "" or <>. Exactly where the compiler looks in each case is compiler specific, not language specific.
|
Steve++
Member #1,816
January 2002
|
Josh, you can also press "Send to Top", which bumps your thread to the top of the list and highlights it, but use that feature sparingly - only when you edit a post significantly and think that people may be interested in the changes. |
joshua.tilson
Member #7,552
July 2006
![]() |
Steve++ said: Josh, that tutorial is quite old, so there may be some things in there that have been deprecated. Is there anything newer i can take a look at? Kauhiz said: Josh, that tutorial is quite old, so there may be some things in there that have been deprecated. not sure where ot start on this either, A kick in the right direction would be great! LennyLen said: I have attached the code for a simple program that creates a skeleton class with more than one member function and then uses it. Try compiling it to see if you get the same error I got it and compiled it and it worked fine! course I am on my work computer now and not at home. I have never encountered that problem before done a few simple classes with many member functions and never had that happen... probably a simple typo or somehting oh well! once again, thanks for the help and advice every one! Josh |
LennyLen
Member #5,313
December 2004
![]() |
Quote: I have never encountered that problem before done a few simple classes with many member functions and never had that happen... probably a simple typo or somehting oh well! The fact that I can compile the same code without that error would indicate otherwise.
|
|