|
in your implementation of init() yes, I understand that, what I was referring to was the desired behaviour of being able to create and instance of some object and then call init() on that object, all in the constext of a ::create() call. This would then chain all the functionality together in the virtual init()'s.
|
|
|
|
|
> This would then chain all the functionality together
> in the virtual init()'s.
Are you implying that making member function virtual does 'chaining'? It's not the case, at least with C++ - you'll have to chain manually inserting base::init in derived::init. Virtual makes no difference here.
If you plan to create Foo only in static Foo::create (as you've mentioned before in this thread), then your init() doesn't have to be virtual at all. Inside Foo::create you have pointer to well-known Foo type, and there's no need to make init() virtual.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
again, I understand the implementation techniques for virtual functions. However, NOT making the init() function virtual means you will not be able to do have this behaviour - rememeber that Foo will have to derive from some base class.
i.e.
class Base {
virtual void init() {
//do something
}
static Base* create() {
Base* result = new Base();
result->init();
return result;
}
};
class Foo : public Base
{
virtual void init() {
Base::init();
//do some more stuff
}
static Foo* create() {
Foo* result = new Foo();
result->init();
return result;
}
};
so calling
Base* b = Base::create()
means Base::init() gets called
while
Foo* f = Foo::create()
results in Base::init() and Foo::init() getting called. If init() was not virtual this would not work, correct ?
|
|
|
|
|
> If init() was not virtual this would not work, correct ?
Not correct. It would work without any problems as non-virtual. Note that the local variable 'result' in static Foo::create is of type Foo, not Base. The compiler will insert the direct call to Foo::init if init would be nonvirtual. If init() would be virtual, the generated code would use the vtable to jump indirectly to Foo::init. You'll get identical results.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
OK now I see what you're saying, which makes sense I guess, and I suppose there is a small performance increase. Learn some thing new every day
Thanks
|
|
|
|
|
Nice design! Do you plan to use Smart pointers too?
|
|
|
|
|
Yes, although this would be optional. I wanted the refcount implicit in the design so the pointers can be used without smart pointers if neccessary.
|
|
|
|
|
You may be interested to look at a similar scheme that is used by the open source package Visualization Toolkit. They use a scheme like this and have put a lot of thought into making it robust and fast.
They point out that you can do a lot of good optimizing if you can be sure that all objects are allocated on the heap (as opposed to global variable memory or on the stack), so they use static member functions New() and Delete() similar to your create() and destroy() .
|
|
|
|
|
|
I need to read from the file a list of persons(person it is a struct that I defined)in unknown size , but I success to read only the first person.
then my loop being infinite.Why ??? What can I do ???
_______MY CODE___________________________________________
void CRegWinDlg::read_persons(CFile* persons)
{
person* q = new person;
if file.Read(q, sizeof(person)))
{
q->next = q->back = NULL;
p_head = p_tail = q;
}
else
{
MessageBox("Have not register of users ! ");
delete q;
return;
}
//---------------------------------- Until here it is working excellent !!!
file.Seek(sizeof(person), CFile::current);
while(file.GetPosition() != CFile::end )
{
p_person q = new person;
if(file.Read(q, sizeof(person)))
{
q->next = NULL;
q->back = p_tail;
p_tail->next = q;
p_tail = q;
}
else
delete q;
file.Seek(sizeof(person), CFile::current);
}
}
|
|
|
|
|
|
Geez, it was only like 40 minutes. Anyway, why are you calling Seek()? The file pointer automatically gets advanced when you read from the file.
|
|
|
|
|
I dont think you need to call Seek since Read advances the position. Also CFile::end, cannot be used to determine the end of the file... it is used for seeking from the end of the file.
You could try something like this;
...<br />
DWORD dwRead = 1;<br />
<br />
while ( dwRead > 0 ) {<br />
<br />
p_person q = new person; <br />
<br />
if ( 0 != ( dwRead = file.Read ( q, sizeof ( person ) ) ) ) {<br />
<br />
q->next = NULL;<br />
q->back = p_tail;<br />
p_tail->next = q;<br />
p_tail = q;<br />
<br />
}<br />
else {<br />
<br />
delete q;<br />
<br />
}<br />
<br />
}<br />
...
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hello All,
I have my App as a SDI, With the CFormView as the base class of the view class. the problem is this,
when maximize the Main App window (to fill the screen) the Form doesn't get resized to fill the App main window, but it stays at its original size and location.
I was wondering if there is a way to get the view form (dialog) gets resized to fill the App main window when I maximize the App window, and to Get it to be resized to fill the App window if I resized the App.
Basically I want the View Form to occupy the App Main window at all times.
Thanks in advance.
Fady.
|
|
|
|
|
I need to be able to build my project with different IDR_MAINFRAME icons.
is this possible? given that VC will rewrite resource.h and myapp.rc, there's no chance of putting and #ifdefs in there.
anyone ever do this?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Each resource (dialog, icon, menu, etc) has the 'Condition' field in its property sheets accessed directly from the Resource View. It can contain the preprocessor symbol - the resource will be included only if the symbol is #defined. This gives you the chance to conditionally change the resource contents.
Unfortunately, VC IDE has apparently some bug here. Sometimes your resource condition changes from SYMBOL to "SYMBOL" - the quotes appear automagically and destroy your carefully crafted solution.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi All !
Please help who is able to
I am creating a component that will provide information to several different client applications. Some of these applications have higher priority than others, and the component must prioritize requests for information.
I'd like to develop this component as COM server component that accepts a reference to a notification object(with Priority property) from each And use asynchronous callbacks to pass information back to the client applications in order of priority
Well, what type of COM server I should rather use ?
Thanks.
|
|
|
|
|
Does your server need to be in-proc?
Is there an interprocess communication between clients through the server?
Do you need to have one server per all clients? i.e. singleton?
If your sever is a singleton, then I guess you should make it out-of-proc
Good luck!
Mh2!
|
|
|
|
|
Hi, I have 2 processes that communicate through a mailslot. The mailslot is created using CreateFile and data is being sent using WriteFile. The mailslot performs well for some time before it crashes. I notice that every WriteFile function returns Error 59 ("ERROR_UNEXP_NET_ERR") .
I never send more that 1.4 kb of data and mailslot is created between 2 processes in the same computer (max data transfer is 64 kb). Any idea anyone .... Any help is greatly appreciated....
|
|
|
|
|
I have created a button control that has an Enable property. I also have a MultiLine property. When the button's Enable property is set to false, the image (caption in this case) is embossed.
// Now draw the caption
if (NewState & ODS_DISABLED)
{
// BUG with multiline when the button is disabled
CPoint pt = CPoint(ClientRect.left, ClientRect.top);
CSize NewcsSize = pDC->GetTextExtent(NewCaption);
pDC->DrawState(pt, NewcsSize, NewCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
}
else
{
pDC->SetTextColor (GetSysColor(COLOR_BTNTEXT));
pDC->DrawText (NewCaption, &ClientRect, DT_WORDBREAK);
}
This works fine until I set the MultiLine property to true. The Caption is still embossed, but instead of breaking the word I get the '|' symbol where the wordbreak should be. Of course MultiLine works fine if the Enable property is set to true. Does anyone know what I am doing wrong here? I am using DrawSate if the button is disabled and DrawText if it is enabled. Any suggestions would be great.
|
|
|
|
|
I have a dialog application which performs a registry backup. I need to perform the same functionality from the command line without showing the frontend.
I have looked into m_lpCmdLine function but I don't fully understand how to setup all of my commands.
I need to be able to consider the following: -
1)My program is called "Registry Backup"
2)Establish whether it needs to be imported or exported e.g. /Export or /Import
3) Then include the possibilty of entering a filename for Local_machine and/or current_user.
I have no idea how to do this. I know I have to do it in InitInstance() with the m_lpCmdLine function but I am now lost.
Thankyou in advance.
|
|
|
|
|
just use __argc and __argv. they behave exactly like the C argc and argv parameters.
run down argv and parse the command line parameters yourself. or, use one of the many command line parsing classes around: here's one
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if ( (argc > 1) && ((*argv[1] == '-') || (*argv[1] == '/')) )
{
if ( _stricmp( "export", argv[1]+1 ) == 0 )
{
CmdExport();
}
else if ( _stricmp( "import", argv[1]+1 ) == 0 )
{
CmdImport();
}
exit(0);
}
}
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
You have to ignore my ignorance but I am reasonably inexperienced in this particular area.
I am working in a Dialog application in the InitInstance function therefore the old style isn't as appropriate how can it be modified. I understand that __argc and _targc are appropriate in this case. Is this true and how does it alter from what you have already posted.
Thanks for your help
|
|
|
|
|
this isn't specific to dialog apps (works fine in doc/view, too):
BOOL CThumb7App::InitInstance()
{
...
if (__argc > 1)
{
firstParam = __argv[1];
}
else
{
firstParam="";
}
...
}
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|