Author Topic: classesin c and c++  (Read 3222 times)

0 Members and 1 Guest are viewing this topic.

Offline jamortTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
classesin c and c++
« 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];
                };
}
 
               
               
               
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

Offline mdmedlin

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 1
Re: classesin c and c++
« Reply #1 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 *
Do or do not, there is no try yes I changed my picture, it is of my daughter.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: classesin c and c++
« Reply #2 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.

Offline jamortTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
Re: classesin c and c++
« Reply #3 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();
}
« Last Edit: June 28, 2009, 10:52:03 AM by jamort »
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: classesin c and c++
« Reply #4 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 ;)

Offline jamortTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
Re: classesin c and c++
« Reply #5 on: June 28, 2009, 10:10:53 PM »
but i swear ive seen programs without functions before ??? idk though problem solved
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: classesin c and c++
« Reply #6 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.

Offline mdmedlin

  • Full Member
  • ***
  • Posts: 73
  • Helpful? 1
Re: classesin c and c++
« Reply #7 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 ;)
Do or do not, there is no try yes I changed my picture, it is of my daughter.

Offline jamortTopic starter

  • Supreme Robot
  • *****
  • Posts: 375
  • Helpful? 2
Re: classesin c and c++
« Reply #8 on: June 30, 2009, 02:29:47 AM »
you ever applied classes to your robots?
my english teacher once said, "dont talk about what you dont know in public...."

so I replied the truth, " Exactly why I dont ever talk about English."

 

SMF spam blocked by CleanTalk