Jump to content
  • Advertisement

redwingdw

Member
  • Content Count

    58
  • Joined

  • Last visited

Community Reputation

122 Neutral

About redwingdw

  • Rank
    Member
  1. Hi the guy actually needs to machines done thats what those extra prototypes are about but If I can get displaying(dev_machine) head->cdata->fieldx then moving on to display the next set of fields I should be ok. sorry about some of the old unused variables but I was looking out some of my old linklists but just couldnt make things work as its been so long since Ive used one
  2. Hi I managed to code a link list for a friend and it displayed all the elements correctly, now they have lost that code and I am trying to do it again but I cant remember how I made it work :-) The problem with the following program is I add to the link list then head becomes head next and after adding its at the end of the list then when I go to display the last record is the only one that gets printed. How can I get it do display all records using recursion and no bounds numbers or such? Also I use the c++ new command to allocate memmory but other than that I want to use basic c procedural methods. heres the current source: #include<stdio.h> #include <stdlib.h> #include<string.h> struct node * init(struct node *head); struct dev_machine * init_dev(struct dev_machine *); struct b12_machine * get_order_b12(struct b12_machine *,struct node *); struct dev_machine * get_customer_dev(struct dev_machine *,struct node *); struct node * add_order_b12 (struct node*,struct b12_machine *); struct node * add_order_dev (struct node *,struct dev_machine *); struct node * del_order (struct node *head); void dev_display (struct node *head); int menu (void); struct b12_machine { char cname[20]; char custemail[30]; int product_ordered; int amount_req; }; struct dev_machine { char cname[20]; char custemail[30]; char product_ordered[30]; int amount_req; }; struct node { struct node *next; struct node *f; struct node *current; struct dev_machine *cdata; //int flag; }; // struct node *start; struct node *temp; struct b12_machine *b12; struct dev_machine *dev; struct node *thefirst; struct node *head; void main() { struct node *hpack; struct node *pnode; //keep all int declarations together assigments only after declarations int choice; head = init(head); dev = init_dev(dev); temp = NULL; start = NULL; hpack = NULL; pnode = NULL; thefirst = NULL; do { choice = menu(); switch(choice) { case 1 : dev = get_customer_dev(dev,pnode); pnode = add_order_dev(pnode,dev); break; case 2 : //this is the B12 temp = del_order(temp); break; case 3 : dev_display(pnode); break; case 5 : break; } }while(choice != 5); printf("It is alive \n"); } struct node * init(struct node *head) { head = NULL; return head; } struct dev_machine * init_dev(struct dev_machine *dev) { dev = NULL; return dev; } struct dev_machine * get_customer_dev(struct dev_machine *dev,struct node *pnode) { //store machine dev cust details in the *dev pointer and return the filled pointer back dev = new dev_machine; printf("Enter Customer Name: \n"); //scanf("%s",cdata->cname); fflush ( stdin ); gets(dev->cname); fflush ( stdin ); printf("Enter Customer Email: \n"); scanf("%s",dev->custemail); fflush ( stdin ); printf("Enter Product: \n"); //scanf("%s",&dev->product_ordered); gets(dev->product_ordered); fflush ( stdin ); printf("Enter quantity required: \n"); scanf("%d",&dev->amount_req); fflush ( stdin ); /*printf("name is succesfully %s \n",dev->cname); printf("email is succesfully %s \n",dev->custemail); printf("product is succesfully %s\n",dev->product_ordered); printf("quantity is succesfully %d \n",dev->amount_req);*/ return dev; } // display user menu int menu (void) { int choice; printf("Enter number 1 to add a plain or rum and raisin order [Devonian] \n"); printf("Enter number 2 to add a plain or cherry order [The B12] \n"); printf("Enter number 3 to display contents \n"); printf("Enter number 5 to exit program \n"); scanf("%d",&choice); return choice; } struct node * add_order_dev (struct node *pnode,struct dev_machine *dev) { //if structure not in place allocate memory and construct if(pnode == NULL) { pnode = new node; pnode->cdata = dev; pnode->current = pnode; pnode->f = NULL; pnode->next = NULL; return pnode; } pnode->next = add_order_dev(pnode->next , dev); } struct node * del_order (struct node *head) { //Check if head is empty if(head == NULL) { printf("The queue is already empty ...cannot delete from an empty queue\n"); // if head not empty delete head }else{ printf("deleting from head of queue...please display contents to confirm\n"); head = head->next; return head; } } void dev_display (struct node *pnode) { if(pnode == NULL) { printf("Queue does not have pending Orders add some more \n"); }else { printf ("customer name is %s \n", pnode->cdata->cname); dev_display (pnode->next); } } struct node * del (struct node *head) { //Check if head is empty if(head == NULL) { printf("The queue is already empty ...cannot delete from an empty queue\n"); // if head not empty delete head }else { printf("deleting from head of queue...please display contents to confirm\n"); head = head->next; return head; } }
  3. redwingdw

    need to pass a C++ object to another class

    Yahoooo Finally :-)))) sorry about that last comment , I had started another project and forgot to include the image files DOW!!!! Well that is the first time Ive used includes and extern variables, Ive fixed this problem and Ive learned a heap so 100% no more questions from me on this thread :-))
  4. redwingdw

    need to pass a C++ object to another class

    No problem :-) I have one more problem , I have read the article and I have a few global variables which used to be in main.cpp anyway I put them in a file Globals.h: #ifndef GLOBALS_H #define GLOBALS_H #include <SDL/SDL.h> #include <stdio.h> #include<string> #include <SDL/SDL_image.h> #include<iostream.h> //set global vars for screen width height and bts per pixel they are constants extern const int SCREEN_WIDTH; extern const int SCREEN_HEIGHT; extern const int SCREEN_BPP; extern const int BALL_SPEED; extern const int BAT_SPEED; //The frame rate extern const int FRAMES_PER_SECOND; //set dot attribs extern const int ball_h; extern const int ball_w; //set global surfaces //SDL_Surface *dot = NULL; extern SDL_Surface *screen; extern SDL_Surface *bat_player; extern SDL_Surface *bat_cpu; extern SDL_Surface *ball; extern SDL_Rect* clip; //The event structure extern SDL_Event event; #endif I also have a file globals.cpp with the variable immplementation: #include "Globals.h" const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; const int BALL_SPEED = 2; const int BAT_SPEED = 1; //The frame rate const int FRAMES_PER_SECOND = 20; //set dot attribs const int ball_h = 40; const int ball_w = 40; //set global surfaces //SDL_Surface *dot = NULL; SDL_Surface *screen = NULL; SDL_Surface *bat_player = NULL; SDL_Surface *bat_cpu = NULL; SDL_Surface *ball = NULL; SDL_Rect *clip = NULL; SDL_Event event; the problem is in main when I call sdl_init it fails to init the screen , this worked no problem before having includes and Im thinking its to do with the globals file : heres my main includes #include <SDL/SDL.h> #include <string> #include <stdio.h> #include <vector> #include <SDL/SDL_image.h> #include<iostream.h> #include "Globals.h" #include "Trajectory.h" #include "PaddleP.h" #include "PaddleC.h" #include "Ball.h" #include "Draw.h"
  5. redwingdw

    need to pass a C++ object to another class

    I tried that earlier then got a "Class type re-definition error" but I put in a #ifndef TRAJECTORY_H #define TRAJECTORY_H class header #endif which seemed to fix it :-), I also found a good article that Ive just started reading which I will submit. That stuff you submitted above has really helped enigma ! cheers all David http://www.gamedev.net/reference/articles/article1798.asp
  6. redwingdw

    need to pass a C++ object to another class

    Quote: class Trajectory; <-------this is a trajectory forwrd declaration in the Ball.h file but it doesnt fix the Trajectory move line class Ball public shape { Trajectory movements; //creates a default trajectory object to be gotten at a later time } where I do Trajectory movements in the class header I get an error and I have done a forward declaration but it still doesnt work , thats what I was getting at in the end. How could I fix this? If its a forward declaration why is it not working ? and which other class is it needed in if not the above? Yes I have done as enigma has suggested and solved the circle problem but I know have a problem with Trajectory moved; line even though I forward declared it thanks
  7. redwingdw

    need to pass a C++ object to another class

    Im getting there now but I have come up against another unique problem in regards to including , In my Ball class definition in the Ball.h file I want a Refference up where the variables get re assigned , a referrence to Trajectory (I may take this out but knowing how to do this is getting my knowledge up) e.g class Trajectory; class Ball public shape { Trajectory movements; //creates a default trajectory object to be gotten at a later time } Im getting a "moved undeclared identifier" error......once again Im probably getting my wires crossed with java as doing this wasnt a problem, I realise the above is not a null pointer as opposed to java which is the way I want it. I have tried including Trajectory.h in ball.cpp, I believe I also tried to include Trajectory.h in ball.h but that didnt fix it. I know know howto do class forwarding roughly which has sorted alot but I need to know how to deal with objects in class definitions? Thanks alot David
  8. redwingdw

    need to pass a C++ object to another class

    God dam lol I must have tested my old way of doing it before going through enigmas guide :-) above, I am know getting 0 errors and dont need to set it as const I did #include "Shape.h" class PaddleC; class Trajectory: public Shape{ public: float speed; Trajectory(); void center_cpu_paddle_colbox(PaddleC & CpuPaddle); }; Trajectory.cpp void Trajectory::center_cpu_paddle_colbox(PaddleC CpuPaddle) { } thats the referrence fixed , Im back to include hell :-) but its not as bad as it was
  9. redwingdw

    need to pass a C++ object to another class

    ahh thanks and dam! ......hmm Im thinking here and of hand I just need various paddle values as the paddle moves......but I wont actually be changing the paddles members from trajectory. I will be using the paddles on each loop iteration with the ball object and altering the collision boxes as the paddlep, paddlec and ball move, the collision arrays are in trajectory. I know its not ideal :-).....but the trajectory object is done in main so I figure it will stay in scope and the arrays should be okay to update through it.......sorry vectors thanks
  10. redwingdw

    need to pass a C++ object to another class

    Just to update Ive looked at the latest error to do with const and lvalues and as a few people have put it .......its to cryptic , can someone show me a fix (still passing the object) that relates to my code. I know people will say its wrong for me to pass an object in this way when they look at the latest error but I want to be able to do it anyway.
  11. redwingdw

    need to pass a C++ object to another class

    This error message is something deeper than the includes now i think, heres the rest of the error A reference that is not to 'const' cannot be bound to a non-lvalue headache material lol
  12. redwingdw

    need to pass a C++ object to another class

    Have got from 100 odd errors down to 1 error by studying what was said I am now getting the following error: c:\mycgames\sdl_cprojs\pongo\pjmain.cpp(275) : error C2664: 'center_cpu_paddle_colbox' : cannot convert parameter 1 from 'class PaddleC *' to 'class PaddleC &' heres my setup main ( PaddleC CpuPaddle; theTraj.center_cpu_paddle_colbox(&CpuPaddle); } then in trajectory: #include "Shape.h" class PaddleC; class Trajectory: public Shape{ public: float speed; Trajectory(); void center_cpu_paddle_colbox(PaddleC & CpuPaddle); }; now in Trajectory.cpp #include "Trajectory.h" #include "PaddleC.h" void Trajectory::center_cpu_paddle_colbox(PaddleC & CpuPaddle) { } I think Im nearly there, I dont get how this is syntactically incorrect
  13. redwingdw

    need to pass a C++ object to another class

    Thanks enigma, I MAY be getting somewhere using include files but what a knightmare to get the order right at this point! ....I am using #ifndef HEADERFILENAME_H #define HEADERFILENAME_H class definition goes here #endif Actually what you said about immplemention files when using includes ......may have solved another problem, you see my OO experience is from java and I was putting the class definition and immplementation in the same file ......I am getting when calling the class constructor from main a not a class or namespace error ....my class definitions arent erroring at this point so Im hoping that means if I put immplementation files in everything will work but I will check that out later (Im going for a break :-) ) Thanks as always for the help, I know im asking alot but Im getting an solving quite a few problems on a daily basis so I am making ground, whats ironic is my program maths and collision boxes worked as intended thus far but it was my program structure thats came back to haunt me. A person on this forum already advised me to use includes and include gaurds but I didnt want to become bogged down with technicalities when I was determined to actually follow 1 project through ). It seems I am going to have to get used to includes though hehe, theres know way around it that I can see when trying to do a game pure OO(Well Ive no doubt it can be done :-) but not from me at this point) David
  14. redwingdw

    need to pass a C++ object to another class

    I have Trajectory getTraj(); method prototype in the class PaddleP and PaddleC which is why I cant move PaddleC and P above trajectory in the file to fix this, even with includes its like Im in this vicous circle where both classes need to know of each other but only 1 knows about the other and not vica versa if you get what Im saying. How would you folks get around this?
  15. redwingdw

    need to pass a C++ object to another class

    ok I have changed to public shape as suggested , I think the problem is to do with the order my classes are in; in my file:(I have tried using includes but I get the same problem ......because PaddleC needs to have a referrence to trajectory but trajectory also needs to deal with paddlec paddlep and ball objects passed in to handle collision detection heres the structure as written in the file: Class Timer{} class Shape() Class Trajectory: public shape {} (if I put paddleP above this it may fix the problem but then I get a problem with tha trajectory reference in the paddlep class) Class PaddleP: public shape{} class Frame {} class Draw public Frame{} Class PaddleC: public shape{} class Ball: public Shape {} main ^^the above is the exact order everythings in the one file , I have tried the classes in includes using ifndef etc but I still get the same problem ......its like Im in include hell lol . I just want to be able to pass objects to other classes. Unless there is something wrong with the way Im passing the PaddleC object? And why was I able to Pass a Shape *ashape object to the same class with no error?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!