• Advertisement
Sign in to follow this  

Dev-C++

This topic is 4678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ummm, there is something wrong with my Dev-C++ compiler, for some reason, when i try and compile my win32 program, it has an error about the constructor/destructor, it doesnt know what they are, it thinks im trying to make a function with no function type. Well how would i fix this?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by dustydoodoo
No No, its not my code, its the compiler, because it compiles with my other compiler (Borland 5.5).

All compilers are different. You may have to make some changes to your code to get it to work on multiple compilers.

Share this post


Link to post
Share on other sites
Quote:
Original post by dustydoodoo
No No, its not my code, its the compiler, because it compiles with my other compiler (Borland 5.5).


The reason we ask to see code is that it is not cross compiler compliant. If you have code that works in Visual Studio 6, it might not work in Visual Studio 7. It could perhaps work in Dev-CPP. If I took code from Dev-CPP, I'm sure Borland might have some troubles with a few things.

As long as you are using the most recent version of Dev-CPP 4.9.9.2 Beta, the compiler works well, it just does not like something in your code. That's the best way to explain this.

Share this post


Link to post
Share on other sites
fine, here is my code (the part with the problem)


SetDefault()
{
BitmapLoaded = false;
}

~Bitmap()
{
DeleteObject(bitmap);
}

Share this post


Link to post
Share on other sites

SetDefault()
{
BitmapLoaded = false;
}

Needs to be:

void SetDefault()
{
BitmapLoaded = false;
}


You must specify the return type for non-constructors/deconstrctors.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton

SetDefault()
{
BitmapLoaded = false;
}

Needs to be:

void SetDefault()
{
BitmapLoaded = false;
}


You must specify the return type for non-constructors/deconstrctors.


WHAT!!?? But i need that constructor/destructer

Share this post


Link to post
Share on other sites
Quote:
Original post by dustydoodoo
Quote:
Original post by Drew_Benton

SetDefault()
{
BitmapLoaded = false;
}

Needs to be:

void SetDefault()
{
BitmapLoaded = false;
}


You must specify the return type for non-constructors/deconstrctors.


WHAT!!?? But i need that constructor/destructer

SetDefault() is not a contructor unless the class name is SetDefault. You can call SetDefault() from the constructor
Bitmap()
{
SetDefault();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by dustydoodoo
Well then whats wrong with the destructor!?

I dont know. What errors are you getting? Maybe you should post the entire class.

Share this post


Link to post
Share on other sites
Quote:
Original post by dustydoodoo
Never mind!, this stupid Dev_c++ is messed up!! im not using it anymore!


--ratings for blaming the IDE for your incompetence.

I think mike25025 is right, but we won't know for sure until you post your whole class.

Share this post


Link to post
Share on other sites

class Bitmap
{
private:
bool BitmapLoaded;

public:
HBITMAP bitmap;
unsigned short int x;
unsigned short int y;


~Bitmap()
{
DeleteObject(bitmap);
}

void Load(LPSTR name)
{
bitmap = LoadBitmap(name);
}
//DB stands for Display Bitmap
void DB(BUFFER *buffer, int x, int y)
{
DisplayBitmap(buffer, bitmap, x, y);
}

};





I got rid of the constructor, i didnt really need it... i guess.

Share this post


Link to post
Share on other sites
You don't really need the destructor either in this case either, because yours doesn't do anything that the default constructor won't do. If your class had pointers, that would be a different story.

However, you will need a constructor if you want to set defaults. Just make sure that the constructor is named after your class (i.e. void Bitmap()). Don't name it SetDefaults() because that will confuse your compiler.

Dev-C++ uses MinGW, which is an awesome compiler. Therefore if you find that your code doesn't work, it's probably not the compiler's fault.

Share this post


Link to post
Share on other sites
Now that annoys me. Don't blame it on DevC++ for your stupid mistakes. DevC++ kicks ass. lol That function was not even a constructor because it didn't take the name of the class.

Share this post


Link to post
Share on other sites
By the way, what did the error say, exactly? You don't necessarily have to define a constructor if all you want is for the member data to be initialized as NULL. The compiler should not have had any problem with you having a function called SetDefault() other than the fact that you didn't specify a type (i.e., void). What made the compiler think that SetDefault was supposed to be your constructor in the first place? It would be helpful if you posted the whole class definition plus the error message.

Share this post


Link to post
Share on other sites
Dustydoodoo, here is one example of what you can do:

#include <windows.h>

HINSTANCE g_hinstance;

class Bitmap
{
private:
bool BitmapLoaded;

public:
HBITMAP bitmap;
unsigned short int x;
unsigned short int y;

// Deconstructor
~Bitmap()
{
if( BitmapLoaded )
DeleteObject( bitmap );
}

// Constructor
Bitmap()
{
BitmapLoaded = false;
}

void Load(LPSTR name)
{
// In this function, you need two parameters, the first is the HINSTANCE of the program
// To get that you will need to save it from the:
// int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
bitmap = LoadBitmap( g_hinstance, name );
BitmapLoaded = true;
}

//DB stands for Display Bitmap I don't have this data so it's commented out
/*void DB( BUFFER *buffer, int x, int y)
{
DisplayBitmap(buffer, bitmap, x, y);
} */


};

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// You will need to do this!
g_hinstance = hinstance;

return 0;
}




Now that should work just fine, I tried it out myself. For a reference on the LoadBitmap function take a look here.

- Drew

Share this post


Link to post
Share on other sites
Now what you need to do is go to:
Project->Project Options->Parameters->Linker Box and add in this:

-lmingw32
-luser32
-lgdi32

I think that's what you need to add. See if that makes the errors go away. Also, you have to make sure the project is indeed a Win32 Application and not a Console. You might have to make a new project and be sure to choose "Windows Applicaton" to being with, the re-add all your files.

Share this post


Link to post
Share on other sites
well i have the function TimeGetTime() and when i try and compile it it comes up with 1 error, about a linker error and TimeGetTime

Share this post


Link to post
Share on other sites
You know, if you look up these functions on MSDN it'll tell you what libraries to link to and which headers to include. Seriously. Read the manual.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement