|
Yes it works, but it has a drawback. A::VALUE , as so defined, cannot be used in constant expressions like this:
class A
{
public:
static int SIZE;
char array[SIZE];
}; The enum workaround does the trick, though.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
This is From Thinking in C++ book
------------------------------------
Constants
In old (pre-Standard) C, if you wanted to make a constant, you had to use the preprocessor:
#define PI 3.14159
Everywhere you used PI, the value 3.14159 was substituted by the preprocessor
When you use the preprocessor to create constants, you place control of those constants outside the scope of the compiler. No type checking is performed on the name PI and you can’t take the address of PI (so you can’t pass a pointer or a reference to PI). PI cannot be a variable of a user-defined type. The meaning of PI lasts from the point it is defined to the end of the file; the preprocessor doesn’t recognize scoping.
C++ introduces the concept of a named constant that is just like a variable, except that its value cannot be changed. The modifier const tells the compiler that a name represents a constant. Any data type, built-in or user-defined, may be defined as const. If you define something as const and then attempt to modify it, the compiler will generate an error.
You must specify the type of a const, like this:
const int x = 10;
In Standard C and C++, you can use a named constant in an argument list, even if the argument it fills is a pointer or a reference (i.e., you can take the address of a const). A const has a scope, just like a regular variable, so you can “hide” a const inside a function and be sure that the name will not affect the rest of the program.
The const was taken from C++ and incorporated into Standard C, albeit quite differently. In C, the compiler treats a const just like a variable that has a special tag attached that says “Don’t change me.” When you define a const in C, the compiler creates storage for it, so if you define more than one const with the same name in two different files (or put the definition in a header file), the linker will generate error messages about conflicts. The intended use of const in C is quite different from its intended use in C++ (in short, it’s nicer in C++).
------------------------------------
anju
|
|
|
|
|
Hi,
In a CListBox drived class i have a simple task: firstly
write something such as "do some work begin ..." in a listbox.
and then do some work and with a progressbar for show the
process. but here my problem is i don't know why the "do some work begin"
always shown at the end of the progress ?
I really want to show it before the start of the progressbar.
Thanks in advance!
chen
|
|
|
|
|
Try to call listbox.Invalidate() and listbox.UpdateWindow() before performing long operation.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
Hi,
Thanks for your reply!
It is worked by using UpdateWindow().
Another problem, how to make the listbox also shows the current added
strings?
Thanks again!
chen
|
|
|
|
|
I'm asssuming you're adding strings during lengthy operation. You should also UpdateWindow after each AddString.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
But it is not worked due to the vertical scroolBar not at the end of the
ListBox. How to automated operate the vertical ScroolBar in order to show
the most recent added strings?
chen
|
|
|
|
|
Try with CListBox::SetTopIndex. If you pass the index of recently added item, the listbox should scroll to the end.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
|
Hi,
I've developed an application which calls a VB dll.The problem that I have is that when a change is made in the VB dll I must recompile the whole VC++ project.
I would like to know how to call the VB dll without having to recompile the whole VC++ project each time a change is made in the dll.
This is how I call the VB dll:
HRESULT hresult;
CLSID clsid;
CoInitialize(NULL);
hresult= CLSIDFromProgID(OLESTR("dllTGT.Class1"),&clsid);
_Class1 *t;
hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *) &t);
if(FAILED(hresult))
{AfxMessageBox("Creation Failed");
return;}
|
|
|
|
|
In VB project under the settings for component select Binary Compatibilty.
C# is fundamentally broken. - Christian Graus
|
|
|
|
|
|
I have written an ActiveX control using the MFC Wizard. When I try to insert it into another project I get the following error message:
"Unable to open this ActiveX control. Make sure the control contains a valid type library."
Any idea ?
Jonathan de Halleux, Belgium.
|
|
|
|
|
Whether it is possible to change the caret in CEdit with a vertical line to another (for example: blinking or solid rectangle). If yes then how?
Best regards,
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Check ::CreateCaret or CWnd::CreateCaret.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
Yes, but after first click into the CEdit, the caret stands to vertical line again.
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Eugene Pustovoyt wrote:
after first click into the CEdit, the caret stands to vertical line again
You probably have to handle WM_SETFOCUS - call default implementation first and set your own caret next.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
I should not call CEdit::SetFocus() in OnSetFocus()?
There is one more question, various symbols have different width. As to me to adjust width of the caret for any symbol.
Best regards,
Eugene Pustovoyt
|
|
|
|
|
Eugene Pustovoyt wrote:
I should not call CEdit::SetFocus() in OnSetFocus()?
You should, but *before* setting your caret.
Eugene Pustovoyt wrote:
There is one more question, various symbols have different width
You'd probably have to monitor keyboard activity and create new caret whenever it moves to new symbol. Not easy task, IMHO.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
Probably, except for pressing the keyboard it is necessary to control the clicks of the mouse. Yes a task not easy.
I shall try, time is not present a way easier, it to realize.
Many thanks for the numerous help to me, including this.
Best regards,
Eugene Pustovoyt
|
|
|
|
|
I seem to have started to generate memory leaks,
really frustrating ones. I think something very strange is going on.
For Example:
in my Splitter class i declare a sub splitter,
m_pwndSplitter = new CJEXSplitter;
it says this is the source of the memory leak but i definately delete it in the destructor:
CJEXSplitter::~CJEXSplitter()<br />
{<br />
int iTemp = 0;<br />
GetColumnInfo(0,m_szFromLeft,iTemp);<br />
m_pwndSplitter->GetRowInfo(0,m_szFromTop,iTemp);<br />
CWinApp * pApp = AfxGetApp();<br />
pApp->WriteProfileInt(_T("SPLITTER"),_T("FROMLEFT"),m_szFromLeft);<br />
pApp->WriteProfileInt(_T("SPLITTER"),_T("FROMTOP"),m_szFromTop);<br />
<br />
<br />
<br />
if (m_pwndSplitter) <br />
delete m_pwndSplitter;<br />
<br />
}
but then it starts saying i have other memory leaks in places I haven't touched like
in my CMainFrame class at
IMPLEMENT_DYNCREATE(CMainFrame, CUIMainFrame)
and in my document class
IMPLEMENT_DYNCREATE(CExplorerDoc, CDocument)
the killer for me is that it says theres a memory leak here to:-
pDocTemplate = new CSingleDocTemplate(<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS(CExplorerDoc),<br />
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CExplorerView));
whats going on have i gone mad?!?
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Looks like your program is terminated prematurely. Can you put the breakpoint in CYourApp destructor and check if it's actually executed?
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
I did check on all the ones i declared myself that and it yes they are called.
Does IMPLEMENT_DYNACREATE declare some memory aswell, if so where is it deleted?
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Jawache wrote:
Does IMPLEMENT_DYNACREATE declare some memory aswell, if so where is it deleted?
Not really. IMPLEMENT_DYNCREATE provides the functionality of IMPLEMENT_DYNAMIC (MFC's own, primitive form of RTTI) and adds trivial implementation of virtual function CreateObject.
CreateObject is used by the framework to create documents/views/frames. If you see leaks originating in CYourObj::CreateObject, then something is wrong with app cleanup. Or - maybe you're playing tricks with doc/view architecture.
Tomasz Sowinski -- http://www.shooltz.com
** Putt knot yore thrust inn spel chequers. **
|
|
|
|
|
I've managed to find and put a breakpoint in CDocManager::~CDocManager()
and it isn't called!!!!
I've also just noticed in the debug window:-
ASSERT_VALID fails with NULL pointer. <- HUH??
The thread 0x46C has exited with code 3 (0x3). <-- Hmmm...
Detected memory leaks!
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|