Ahhhh!

This is a discussion on Ahhhh! within the C++ Programming forums, part of the General Programming Boards category; Ok, I invented a class to pass an array of ints: Code: #include <windows.h> #include <iostream> #include <string.h> #include <conio.h> ...

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

    Ahhhh!

    Ok, I invented a class to pass an array of ints:

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string.h>
    #include <conio.h>
    #include <fstream.h>
    using namespace std;
    
    class Keeper {
     private:
      SHORT zzx[5];
    
     public:
      Keeper() {zzx[0] = 0; zzx[1] = 0; zzx[2] = 0; zzx[3] = 0; zzx[4] = 0;}
      Keeper(SHORT z, SHORT zz, SHORT zzz, SHORT zzzz, SHORT b) {zzx[0] = z; zzx[1] = zz; zzx[2] = zzz; zzx[3] = zzzz; zzx[4] = b;}
      
      void Check(SHORT x) {zzx[x] = 1;}
      void Uncheck(SHORT x) {zzx[x] = 0;}
      void UncheckAll() {zzx[0] = 0; zzx[1] = 0; zzx[2] = 0; zzx[3] = 0; zzx[4] = 0;}
     
      int IsChecked(SHORT x);
    };
    
    int Keeper::IsChecked(SHORT x) {
     if(zzx[x] == 1)
      return 1;
     
     return 0;
    }
    Pritty elementary, no safety at all. But its driving my compiler nuts:
    Code:
    Error E2294 C:\MOPEngine.h 109: Structure required on left side of . or .* in function IsArrowDown()
    Error E2294 C:\MOPEngine.h 111: Structure required on left side of . or .* in function IsArrowDown()
    Error E2294 C:\MOPEngine.h 113: Structure required on left side of . or .* in function IsArrowDown()
    Error E2294 C:\MOPEngine.h 115: Structure required on left side of . or .* in function IsArrowDown()
    Error E2294 C:\MOPEngine.h 117: Structure required on left side of . or .* in function IsArrowDown()
    Error E2034 C:\MOPEngine.h 119: Cannot convert 'Keeper (*)()' to 'Keeper' in function IsArrowDown()
    Error E2034 C:\MOPEngine.h 363: Cannot convert 'int' to 'Keeper' in function Check(Keeper)
    Error E2034 C:\MOPEngine.h 368: Cannot convert 'int' to 'Keeper' in function Check(Keeper)
    Error E2034 C:\MOPEngine.h 371: Cannot convert 'int' to 'Keeper' in function Check(Keeper)
    *** 9 errors in Compile ***
    IsArrowDown code:
    Code:
    Keeper IsArrowDown() {
     Keeper Zouth();
    
     if(GetAsyncKeyState(VK_UP)&SHRT_MAX)
      Zouth.Check(0);
     if(GetAsyncKeyState(VK_DOWN)&SHRT_MAX)
      Zouth.Check(1);
     if(GetAsyncKeyState(VK_LEFT)&SHRT_MAX)
      Zouth.Check(2);
     if(GetAsyncKeyState(VK_RIGHT)&SHRT_MAX)
      Zouth.Check(3);
     if(GetAsyncKeyState(VK_ESCAPE)&SHRT_MAX)
      Zouth.Check(4);
    
     return Zouth;
    }
    Check code:
    Code:
    Keeper Check(Keeper x) {
    
     if(x.IsChecked(1)==1) {
      MoveRight();
      return 1;
     }
    
     if(x.IsChecked(2)==1) {
      MoveLeft();
      return 2;
     }
    
     return 0;
    }
    It seems to not enjoy the use of my class... But I dont see why its rejecting it? I can post my whole source, but its pritty long and I'd rather avoid it.

    Thank you!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    >> Keeper Zouth();

    This does not declare an instance of the Keeper class, it declares a function called Zouth that returns a Keeper. It is a weird quirk of the language. Remove the parentheses.

    BTW, it should be <fstream>, not <fstream.h>.

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    drop the paranthesis
    Code:
    Keeper Zouth();
    You are returning ints in Check(Keeper x), but you have declared Check(Keeper x) as type Keeper. Change the type to int

    See if that clears the errors

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Lol seriously? Haha, it worked once I moved the paranthases, I didint realise I could declare a function in a function. (Does that make a sub-function only accessable to the function that declared it by any chance?) Well now I'm just left with:

    [edit]
    I guess I missed your last part -,-.

    Thank you!
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ahhhh some ppl !
    By ki113r in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 08-30-2007, 03:02 AM
  2. C program for Class --- DUE TODAY!!! AHHHH
    By Fr0st2k in forum C Programming
    Replies: 6
    Last Post: 09-22-2004, 03:10 PM
  3. AHHHH regedit problems
    By dP munky in forum Tech Board
    Replies: 3
    Last Post: 08-07-2004, 09:59 AM
  4. Ahhhh! Spit!!
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-04-2003, 04:03 PM
  5. sleep... ahhhh...
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2002, 10:53 PM

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