New compiler - Weird errors -,-.

This is a discussion on New compiler - Weird errors -,-. within the C++ Programming forums, part of the General Programming Boards category; (Mingw g++ MSYS compiler, Win32) I'm trying to compile a linked list test I made. It serves no real purpose, ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    Question New compiler - Weird errors -,-.

    (Mingw g++ MSYS compiler, Win32)
    I'm trying to compile a linked list test I made. It serves no real purpose, but its good practice. Anyways, my compiler is giving me error messages that completely confuse me, I dont see why I'm getting theyse. (Picky compiler... >.>)

    Error messages:

    Code:
    $ g++ C:/Test2.cpp
    C:/Test2.cpp: In member function `void WhaWrapper::CoutAll(WhaWrapper, Wha*)':
    C:/Test2.cpp:122: error: expected `;' before ')' token
    C:/Test2.cpp:128: error: expected primary-expression before '}' token
    C:/Test2.cpp:128: error: expected `;' before '}' token
    C:/Test2.cpp:128: error: expected primary-expression before '}' token
    C:/Test2.cpp:128: error: expected `)' before '}' token
    C:/Test2.cpp:128: error: expected primary-expression before '}' token
    C:/Test2.cpp:128: error: expected `;' before '}' token
    Heres my code, CoutAll is highlighted in red. (Feel free to tell me everything I did wrong with the linked list itself :P.)

    Code:
    #include <iostream>
    using namespace std;
    
    #define Next      4
    #define Prev      8
    #define Previous  8
    
     typedef struct Wha *Whaa;
     typedef struct Wha *List;
    
     struct Wha {
      Whaa prev;
      Whaa next;
      int clams;
     };
    
     class WhaWrapper {
      private:
       Wha Confusing;
    
      public:
       WhaWrapper();
       WhaWrapper(int I) {Confusing.clams = I;}
    
      void AddElement(Whaa Pre, Whaa Post);
      void AddBefore(Whaa Pre, Whaa Post);
      void CoutAll(WhaWrapper P, List l);
      Whaa First(Whaa Pre);
      Whaa FirstNext(Whaa Pre);
      Whaa Last(Whaa Pre);
      List Add(List l, Whaa Pre, Whaa Post, int I);
      List Remove(List l, Whaa Pre);
     };
    
     void WhaWrapper::AddElement(Whaa Pre, Whaa Post) {
      if(Pre != NULL || Post != NULL)
       goto end; //Skips to the end.
    
      Post->prev = Pre->prev;
      Post->next = Pre;
      if(Pre->prev != NULL)
       Pre->prev->next = Post;
      Pre->prev = Post;
    
      end:
     ;}
    
     void WhaWrapper::AddBefore(Whaa Pre, Whaa Post) {
      if(Pre != NULL || Post != NULL)
       goto end; //Skips to the end.
    
      Post->prev = Pre;
      Post->next = Pre->next;
      if(Pre->next != NULL)
       Pre->next->prev = Post;
      Pre->next = Post;
    
      end:
     ;}
    
     Whaa WhaWrapper::First(Whaa Pre) {
      while(Pre != NULL && Pre->prev != NULL)
       Pre = Pre->prev;
    
      return Pre;
     }
    
     Whaa WhaWrapper::FirstNext(Whaa Pre) {
      while(Pre != NULL && Pre->prev != NULL)
       Pre = Pre->prev;
    
      return Pre->next;
     }
    
     Whaa WhaWrapper::Last(Whaa Pre) {
      while(Pre != NULL && Pre->next != NULL)
       Pre = Pre->next;
    
      return Pre;
     }
    
     List WhaWrapper::Add(List l, Whaa Pre, Whaa Post, int dir) {
      if(Post == NULL)
       goto end; //Skips to the end.
    
      if(l == NULL)
       l = Post;
      else {
       if(Pre == l && dir == Previous) {
        AddBefore(l, Post);
        l = Post;
       } else {
        if(dir == Previous)
         AddBefore(Pre, Post);
        else
         AddElement(Pre, Post);
       }
      }
    
      return l;
      end:
     ;}
    
     List WhaWrapper::Remove(List l, Whaa Pre) {
      if(l == NULL || Pre == NULL)
       goto end; //Skips to the end.
    
      if(Pre->prev != NULL)
       Pre->prev->next = Pre->next;
      if(Pre->next != NULL)
       Pre->next->prev = Pre->prev;
      if(Pre = l)
       l = Pre->next;
    
      return l;
      end:
     ;}
    
     void WhaWrapper::CoutAll(WhaWrapper P, List l) {
      Whaa start = P.FirstNext(l);
    
      for(start->next != NULL && start != NULL) {
       cout << start.clams << endl;
       start = start->next;
       start->next = start->next;
       start->prev = start->prev->prev;
      }
     }
    
     int main() {
      List l;
      WhaWrapper Prim(2);
      Wha Pox[3];
      int I;
    
      for(I = 0; I != 4; I++) {
       Pox[I].next = NULL;
       Pox[I].prev = NULL;
       Pox[I].clams = I;
       Prim.Add(l, Pox[I].next, Pox[I].prev, Next);
      }
    
      return 0;
     }
    Thanks ...
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    for(start->next != NULL && start != NULL)
    That ain't a for statement (while?)

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    903
    I don't really see the exact problem though I see many things that need to be changed. For example, you call your Wha* typedef Whaa which is a little bit confusing. Couldn't you call it WhaPtr or simply not typedef it ? I mean... why would you typedef a pointer to some type ? I know the Win32 API does it but I think it's just trying to hide pointers uselessly. Anyway. In your CoutAll() function you do 'start.clams' though start is a pointer and requires to use -> instead of '.'.

    Edit: God, how couldn't I see that ? -.-
    Last edited by Desolation; 08-26-2006 at 08:23 PM.

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Lol! I didint realize I meant to put while, I'm to used to using for loops lol! Thanks tonto :P.

    Its a pointer so it can point to the adress of an item. In this case, it needs to be a pointer so it can hold an instance of Wha within Wha's self. I named it Whaa so it would be all the more confusing ';,.,;'. Actualy, I just named it whatever came to mind at 2:30 am :P.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  5. #5
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    typedef struct Wha *Whaa;
    why do people do this...?
    My Website
    010000110010101100101011
    Add Color To Your Code!

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by mrafcho001
    Code:
    typedef struct Wha *Whaa;
    why do people do this...?
    Often, just for readability. Sometimes, it can be useful to give shorter, and more meaningful names to complicated data types, eg.
    Code:
    typedef unsigned long int TaskID_t;
    typedef std::map<TaskID_t, std::string> Tasklist_t;
    This could give extra clarity as to the purpose of the std::map, as well as saving the user of the code some typing each time he wishes to instantiate a new object.


    Edit : perhaps you meant "Why do people put the struct keyword in typedefs"? Possibly out of habit or consistency with legacy 'C' code, where the struct keyword is needed in 'C' to instantiate an object of a struct. Often typedefs are used in C to avoid having to use the struct keyword each time.
    Last edited by Bench82; 08-27-2006 at 05:37 AM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Typdef'ing pointer types is poor form IMO, with the exception of pointers-to-functions.
    All that work just to save typing a single * later on in the code.

    But that's not the end of it, you have to then look back at the typedef to work out the number of real levels of indirection there are for you to work out how to write the code.
    void foo ( char **p );
    vs.
    typedef char * cp_t;
    void foo ( cp_t *p );

    Also, when you start qualifying the pointers with const for example, then the typedef pointer gets in the way of doing certain things, eg.
    void foo ( char * const *p );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,435
    if(l == NULL)
    l = Post;
    else {

    /* ... */

    if(l == NULL || Pre == NULL)
    goto end;
    If you understand the concept of IF... ELSE, why then you chose to use GOTO on that other if statement? Don't.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by Mario F.
    If you understand the concept of IF... ELSE, why then you chose to use GOTO on that other if statement? Don't.
    Yep, goto is one of the cardinal sins of any (modern) programming language.
    For the OP: if you ever wish to break out of a loop statement, then use the keyword break. If you are trying to get out of a function, then you should use return. and if you are trying to exit your program altogether, then you can use exit() from <cstdlib>
    Last edited by Bench82; 08-27-2006 at 07:30 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Weird errors.
    By Desolation in forum C++ Programming
    Replies: 20
    Last Post: 05-09-2007, 01:10 PM
  3. compiler errors
    By Draco in forum C++ Programming
    Replies: 3
    Last Post: 10-25-2003, 11:08 AM
  4. Borland's compiler is... weird
    By Yoshi in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-18-2002, 08:12 PM
  5. Compiler errors
    By BellosX in forum C Programming
    Replies: 2
    Last Post: 09-21-2001, 03:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21