Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi and good morning to all the users of code project,
i'm now try to make a program with an additional of .cpp file, or may be will more then 1, but i never make it before, and i wonder what is my problem, even I already insert my header file into my main cpp file, at the same time I already make the declaration, but when i tried to compile my code, it shown me that, I haven't declare it, but actually i already declare it in my main cpp files,*please take note that i already insert my main header file into my secondary cpp file as well* then i tried to make another declaration into my secondary cpp*Actually i know it won't work, but i just try my luck*, another error messagebox show that, i had make my declaration in the main page, so any suggestion or solution for me??

thanks,

Rgds,

illm1995
Posted
Comments
Sergey Alexandrovich Kryukov 30-Sep-12 22:24pm    
Calm down, it's not fatal. If you knew it won't work, why pointless "trying your luck". You did not even properly explained the problem. Just do everything properly, and do it by yourself.
--SA
illm1995 30-Sep-12 22:32pm    
for an example,
I declare int a in main .cpp file,
when i try to call it in my secondary .cpp file, it show me the error message box that i haven't make the declaration*int a" yet
Sergey Alexandrovich Kryukov 30-Sep-12 23:07pm    
First of all, there is no such thing as "call a file". After all, make a simplest code sample: some 3 files, one extra declaration, and show it all, with file names. Here, we almost don't have members who only compiled an application with only one file, I believe, most of us are a bit more advanced than that, so, will sort it out somehow... :-)
--SA

1 solution

In your second .cpp, make it as extern
C++
extern int a;
 
Share this answer
 
Comments
illm1995 1-Oct-12 0:00am    
Thank you, but now I'm facing another problem in my 2nd cpp as well, that are messagebox, the compiler did not recognize the command of 'L' and 'MB_OKCANCEL', 'MB_ICONWARNING'.. is there any solution??

Thanks You,

Rdgs,

Illm1995
illm1995 1-Oct-12 0:01am    
Sorry for interrupt you anyway. @@
Kuthuparakkal 1-Oct-12 0:16am    
Add winuser.h
or declare like this :
private const uint MB_OK = 0x00000000;
The other uint values :
MB_OK is 0x00000000L
MB_OKCANCEL is 0x00000001L
MB_ICONWARNING is 0x00000030L
illm1995 1-Oct-12 0:25am    
Sorry to say, it does not work :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900