Jump to content
  • Advertisement
Sign in to follow this  
kecebongsoft

Undeclared Indentifier in C++

This topic is 4576 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

I am a newbie on C++ Programming, am trying to declare HBITMAP in other file (test.cpp), but i've got message "HBITMAP undeclare identifier", here's the source : FILE main.cpp #include "windows.h" #include "test.cpp" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ return 0; } FILE test.cpp void test(){ HBITMAP hBmp; } Well, what's wrong with my code?, i try to place #pragma comment(lib,"gdi32.dll") and #include "windows.h" in test.cpp, but i've got no better :(.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
#include

Share this post


Link to post
Share on other sites
to roboguy:
I was put #include "windows.h" in test.cpp, but i've got message that tell me void test already declared in main.obj. Can anyone give me some samples please?

Share this post


Link to post
Share on other sites
if I remove #include "test.cpp" in main.cpp, i'll get error(undeclared identifier) when I make a class in test.cpp and declared it in main.cpp, my original source is this :

FILE main.cpp
#include "windows.h"
#include "test.cpp"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
test myBitmap;
return 0;
}


FILE test.cpp
#include "test.h"
void test::initBmp{
HBITMAP hBmp;
}

FILE test.h
class test(){
int x,y;
void initBmp();
};

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You shouldn't include cpp files, you should compile them separately. Finally "linker" will link all the separately compiled cpps into one exe or dll or whatever. main.cpp should include test.h, not test.cpp. That way it'll know about the class called "test" and not complain about undeclared identifier.

Share this post


Link to post
Share on other sites
Quote:
Original post by kecebongsoft
if I remove #include "test.cpp" in main.cpp, i'll get error(undeclared identifier) when I make a class in test.cpp and declared it in main.cpp, my original source is this :

FILE main.cpp
#include "windows.h"
#include "test.cpp"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
test myBitmap;
return 0;
}


FILE test.cpp
#include "test.h"
void test::initBmp{
HBITMAP hBmp;
}

FILE test.h
class test(){
int x,y;
void initBmp();
};


Well, first of all, your syntax isn't quite right. You probably meant something like this (there are a few points which are a bit unclear, so I'll have to guess a bit):

// main.cpp
#include <windows.h>
#include "test.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
test testBitmap;
return 0;
}



// test.cpp
#include "test.h"
void test::initBmp() {
// ... do something with bitmap here ...
}

// ... definitions of methods to access the private fields in some way or another ...



// test.h
#ifndef TEST_H
#define TEST_H

class test {
int x, y;
HBITMAP bitmap;
public:
void initBmp();
// ... declarations of methods to access the private fields in some way or another ...
};

#endif

Share this post


Link to post
Share on other sites
Quote:
Original post by kecebongsoft
I am a newbie on C++ Programming, am trying to declare HBITMAP in other file (test.cpp), but i've got message "HBITMAP undeclare identifier", here's the source :

FILE main.cpp
#include "windows.h"
#include "test.cpp"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){
return 0;
}


FILE test.cpp

void test(){
HBITMAP hBmp;
}

Well, what's wrong with my code?, i try to place #pragma comment(lib,"gdi32.dll") and #include "windows.h" in test.cpp, but i've got no better :(.


EDIT: removed by xeddiex...

- xeddiex

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!