Hey guys I just learned how to work with header files but I have a simple error .
I suggest you guys dont look at gameboard.cpp because it just runs fine with ubuntu and no errors with it.
my problem is when I run the main it gives the eroor undifined reference to gameboards::gameboards();
what is the problem . I check the internet and I think it must be working fine
mohre.h :

#ifndef __MOHRE_H
#define __MOHRE_H
struct mohre
    int color;


gameboard.h :

#include "mohre.h"

class gameboards
    public :
    mohre ***gb;
    int timer1,timer2;
    int moverx,movery;
    int goadd;
    void moverdown();
    void movertop();
    void moverright();
    void moverleft();
        void preadd();
    void add();
    void mohreswitch(int x,int y);

gameboard.cpp :

#include <cstdlib>
#include <time.h>
#include "gameboard.h"
#include "mohre.h"

using namespace std;

mohre* goingadd[6];

    gb = new mohre **[6];
    for (int i=0;i<6;i++)
        gb[i] = new mohre *[20];
    for (int i=0;i<6;i++)
        for (int j=0;j<20;j++)

void gameboards::mohreswitch(int x,int y)
    mohre *ali;
    ali = gb[x][y];
    gb[x][y] = gb[x+1][y];
    gb[x+1][y] = ali;

void gameboards::preadd()
    for (int i=0;i<6;i++)
        goingadd[i] = new mohre();
        goingadd[i]->color = rand()%5;

void gameboards::moverright()
    if (moverx<=9)

void gameboards::movertop()

void gameboards::moverdown()

void gameboards::moverleft()

and the main :

#include <iostream>
#include "gameboard.h"
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <string>

using namespace std;

int main()
    gameboards hieee;
    return 0;

Recommended Answers

All 5 Replies

can you please also post where the error is occuring at( like what file )

at the main (in a.cpp):
undifined reference to gameboards::gameboards();

everything looks okay to me :/ add an include guard on the gameboard.h as well. Also remove mhore.h in gameboard.cpp and since it is already in( and should be in ) the gameboard.h file

I think I figured It out by luck , I didnt include the gameboard.h but I include gameboard.cpp!!! and it just started working but tnx for looking at the program

Do NOT #include a cpp file. Do NOT.

The problem here is that you don't understand what the compiler does, what the linker does, and how they work together. Every cpp file should get compiled, and then all of them get linked together. If you're using some kind of IDE, you need to put all the cpp files into your "project" or whatever it's called.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.