Society of Robots - Robot Forum

Software => Software => Topic started by: jamort on June 27, 2009, 06:22:48 PM

Title: classesin c and c++
Post by: jamort on June 27, 2009, 06:22:48 PM
ive never really used classes and im trying to make a chess game and i keep having a problem because I think its the type of information im trying to store or something... I'm trying to get this straight so i can get on with my program.... heres what im trying to do i know its wrong please help..

Code: [Select]
#include<iostream>
 
namespace chess {
          class chess_board{
                int *chess_board[8][8];
                };
}
 
               
               
               
Title: Re: classesin c and c++
Post by: mdmedlin on June 28, 2009, 03:56:19 AM
I believe the problem is how you are naming your array.  I don't think arrays in C can start with *
Title: Re: classesin c and c++
Post by: chelmi on June 28, 2009, 08:43:24 AM
I believe the problem is how you are naming your array.  I don't think arrays in C can start with *

He's declaring a 2D array of pointers to integers, that ok. I don't see anything wrong with this code. I actually compiled it and g++ didn't complain.
Could you give us more details? like the error message you're getting.

By the way, classes don't exist in C.

Chelmi.
Title: Re: classesin c and c++
Post by: jamort on June 28, 2009, 10:48:28 AM
Code: [Select]
#include<iostream>
 
namespace chess {
          class chess_board{
                int *chess_board[8][8];
                };
}

errors:

  [Linker error] undefined reference to `WinMain@16'
  ld returned 1 exit status

im using dev c++ 4.9.9.2... Im not sure what im doing wrong but as I said I've never really used classes...



edit... this is weird i add this and the code works...
Code: [Select]
#include<iostream>
 
namespace chess {
          class chess_board{
                int *chess_board[8][8];
                };
}

using namespace std;

int main(){
    cout<< "Hello there";
    cin.get();
}
Title: Re: classesin c and c++
Post by: chelmi on June 28, 2009, 01:02:13 PM
Your problem is not the class. The compiler is complaining because you don't have a main fuction (called WinMain in windows I guess).
Your fix is not weird at all ;)
Title: Re: classesin c and c++
Post by: jamort on June 28, 2009, 10:10:53 PM
but i swear ive seen programs without functions before ??? idk though problem solved
Title: Re: classesin c and c++
Post by: chelmi on June 29, 2009, 09:23:55 AM
Unless you are writing a library, every program needs a main function. But it can be in a different file.
Title: Re: classesin c and c++
Post by: mdmedlin on June 30, 2009, 12:39:55 AM
oh yeah the pointers I forgot about the pointers thanks for reminding me.  I don't have that much C++ experience, just what I needed to know to get through my data structures class ;)
Title: Re: classesin c and c++
Post by: jamort on June 30, 2009, 02:29:47 AM
you ever applied classes to your robots?