Attribute ignored in member function...?

Started by
1 comment, last by Rombethor 16 years, 10 months ago
I've been trying to make a DLL for part of my 2D game but it's been giving me an error i don't understand... I'm using bloodshed Dev-C++ 4.9.9.2 on windows XP. The code is:

//stdafx.h
#ifndef X2_stdafx_h__
#define X2_stdafx_h__

//all the includes go here...

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <vector>
#include <map>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include <SDL/SDL_mixer.h>
#include <windows.h>

#if BUILDING_DLL
# define DLLIOX2 __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIOX2 __declspec (dllimport)
#endif /* Not BUILDING_DLL */

#endif


//main.h
#ifndef X2_MAIN_h__
#define X2_MAIN_h__

#include "stdafx.h"

using namespace std;

namespace X2{

class DLLIOX2 Game{
      private:
              int bob;
      public:
             Game();
             void Flip();
}Game;


}//end namespace X2

#endif


//main.cpp
#include "main.h"

using namespace std;

namespace X2{

void Game::Flip()
{
}

}// end of namespace X2

I'm getting the error: In constructor 'X2::Game::Game()'; [Warning] attribute ignored In constructor 'X2::Game::Game()'; [Warning] in rest_of_handle_final, at toplev.c:2064 [Build Error] [main.o] Error 1 Any enlightenment is better than none, and if you have any tutorials on writing DLLs it would be apreciated because the the internet seems a bit dry from my screen.
Advertisement
Well I see two problems here :

class DLLIOX2 Game{      private:              int bob;      public:             Game();             void Flip();}Game;


Here you declare a class of type "Game" as well as an instance of this class with exactly the same name, "Game". I don't think C++ allows this. Anyways I don't see why you'd create an instance of this class, so you could simply remove the "Game" at the end of your class declaration like this :

class DLLIOX2 Game{      private:              int bob;      public:             Game();             void Flip();}; // No "Game" here!


Secondly, I'm not sure that C++ DLLs allow exporting classes (in fact I'm pretty sure it does not). However, you might be able to do the following (as long as your dll and app are compiled with the same compiler, else it might not work) :

class Game{ // No DLLIOX2      private:              int bob;      public:             Game();             void Flip();};Game * DLLIOX2 CreateGame();void DLLIOX2 DestroyGame(Game * game);


The DestroyGame function is needed because you cannot destroy a class instance that was created in a dll in your main app, you jave to let the dll delete it itself. So in your .cpp file, you'd add :

Game * CreateGame() { return new Game(); }void DestroyGame(Game * game) { delete game; }


Keep in mind that C++ DLLs and OOP don't go well together.
Hurah! it works now! thanks you ever so much =D

This topic is closed to new replies.

Advertisement