|
Well, from the view of the C++ linker, my previous example code would be something like this:
[the whole pseudo code in one single source file]
int iGlobalNumber;
void main()
{
iGlobalNumber = 2;
}
int iGlobalNumber;
void Test()
{
iGlobalNumber = 1;
}
Regarding to the above issue, you may have a look at chapter 9 or 10 (I forgot) in the book "The C++ Programming Language" 3rd edition by Bjarne Stroustrup.
George2 wrote:
(?iGlobalNumber@@3HA)
C++ uses mangled names to serve polymorphism, overloading, etc.
You can take a look at this link: C++ Name Mangling/Demangling[^]
BuggyMax
|
|
|
|
|
Thanks, BuggyMax buddy!
I have added "extern" keyword before int in main.cpp and mod.cpp, but the error still remains the same. How to resolve the trouble?
regards,
George
|
|
|
|
|
The solution is, you can only declare global variables in *.CPP.
[file mod.h]
#ifndef _MY_HEADER_FILE_H_
#define _MY_HEADER_FILE_H_
void Test();
#endif // _MY_HEADER_FILE_H_
--------------------------------
[file main.cpp]
#include "mod.h"
int iGlobalNumber;
void main()
{
iGlobalNumber = 2;
Test();
}
-----------------------------------
[file mod.cpp]
extern int iGlobalNumber;
void Test()
{
iGlobalNumber = 1;
}
------------------------------------
BuggyMax
|
|
|
|
|
Thanks, BuggyMax buddy!
You have corrected another one of my years-old mistakes.
regards,
George
|
|
|
|
|
i am really real newbie when it comes to c++. i just got the "Teach Yourself C++ in 21 Days" book and it is great. there is a sample code in there that i think everyone knows called the "hello world" code. which is:
#include <iostream><br />
<br />
int main()<br />
{<br />
std::cout << "Hello World!\n";<br />
return0;<br />
}
but in viusal C++ 6.0, i tried to build it, but it gives the error:
Compiling...<br />
hello.cpp<br />
c:\documents and settings\owner\desktop\hello.cpp(6) : error C2065: 'return0' : undeclared identifier<br />
c:\documents and settings\owner\desktop\hello.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed<br />
Error executing cl.exe.<br />
<br />
hello.exe - 1 error(s), 1 warning(s)<br />
i have tried a few other sample codes and they all give me similar errors.
btw, i just installed visual c++ 6.0 standard, and i have made no changes to the settings.
any help would be appreciated. thanks in advance
|
|
|
|
|
Anonymous wrote:
return0;
try:
return 0;
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
i must have reread and retyped that code 4 times and i did not notice that. thanks so much, parths!
|
|
|
|
|
Personally I think return(0) is clearer.
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
depends if you look at return as a function or statement. Personally I prefer return 0; cos, to me, its more of statement, can you imagine going int length = (0); everywhere? Nah me neither.
|
|
|
|
|
But wouldn't life be boring if we all agreed!
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
That it would be . As long as your consistent with whatever style you prefer, thats the main thing, and I'm sure we'll agree on that .
|
|
|
|
|
Dangleberry wrote:
As long as your consistent
100% in agreement, also whenever I am debugging/changing another persons code I try and use the same style as the original programmer, even if I hate it!
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
how do i create the following :
suppose I have a list box A containing several items and another list box B that will display the item selected in list box A each time the user push a "add" button. It should also undisplay the item when a "remove button" is pushed after selecting the item to be removed from list box B.
|
|
|
|
|
void CYourDialog::OnAddButton()
{
CString cText;
int nIndex;
nIndex = m_ComboboxA.GetCurSel();
if(nIndex == CB_ERR)
return;
m_ComboboxA.GetLBText(nIndex, cText);
m_ComboboxB.AddString(cText);
}
void CYourDialog::OnRemoveButton()
{
int nIndex;
nIndex = m_ComboboxB.GetCurSel();
if(nIndex == CB_ERR)
return;
m_ComboboxB.DeleteString(nIndex);
}
|
|
|
|
|
|
How can I add OnOK event in CPropertySheet
from class wizard?
Thanks in advance.
Shinya
|
|
|
|
|
If file is locked or really user have no permission to write to the file?
Thanks,
Brian
|
|
|
|
|
|
but then again, maybe its simpler than that - I wonder if an attempt to open the file would produce a trappable 'no permissions error' - sorry, I cant check this right now (dont have MSDN here at the office)
'G'
|
|
|
|
|
Use the _access api
with which u can check for the access to the file and solve teh bug
Thanx
TAKE CARE
|
|
|
|
|
Sorry no go,
_access calls dosmapper => EACCES when file is locked, when permission denied.
as well as it will lie about write access to network shares. _access will
report file/directory is writable when it isn't.
Thanks,
Brian
|
|
|
|
|
Hi guys
I'm managing a big array and I'm receiving this message when I execute the program (Unhandled exception in ...EXE: stack overflow). What can I do to try to solve it?
It's an array of a class (maybe this helps you to understand the problem).
Best Regards
Dr. Pi
|
|
|
|
|
Stack overflow, as the name implies, means your app process stack memory got overflew, so the best way to solve your problem could be moving your stuff from stack to the heap. Maybe you have put your "big array" of objects in the stack? For example:
My_Obj aObjs[9999]; // this could cause stack overflowing
// allocate them in heap instead:
My_Obj* pObjs = new My_Obj[9999]; // this could work
// ...
delete [] pObjs;
pObjs = NULL;
|
|
|
|
|
Recursive function calls can also cause a stack overflow if they get nested too deep.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I want to get the selected row in
CDataGrid.
Something like
CDataGrid * pGrid;
long l_CurPos = pGrid -> GetCurrentPos();
Thanks in advance.
Shin
|
|
|
|