|
Excellent! That's always the desired outcome
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
Just so that I understand the dervied base concept
Is the only difference between these 2 peices of code the way the code is executed
and Storage lay'ed out
class A : public B, C
{
}
class A
{
class B;
class C:
}
In this first case base class B gets created then C the dervied class A
in the second A gets created then B then C
functionally these 2 peices of code couls act alike ???
thankx
|
|
|
|
|
There's a big difference between multiple inheritance and nested class definition (BTW your second piece of code as it stands would hardly compile), I believe.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ForNow wrote: Just so that I understand the dervied base concept
Your understanding is not accurate/complete. Again, I strongly urge you to do more studying starting with materials that are targeting beginners.
|
|
|
|
|
thought I did apperantly not I have been using Bjarne Stroustrup Book
seems like the best one I'll do more reading
|
|
|
|
|
Hi,
Sorry for delayed response...( as I Sabbath Observing jew)
The Book I am using to teach me C++ programming Language 3rd Edition
By Bjarne Stroustrup
I re-read chap 10 (classes) 12 (derived Classes) and 15 (Class
Heriachies)
In 10.4.6 "Class Objects as Members" there is an example of Nested
classes the autor explains using the example in The Book
class Club
{
string name;
Table members;
Table officers;
Date founded;
that in the above example the Class Club gets contructed first
and then each of the other classes in the order they (the classes)
are declared in the consturcter
in which case the refereced class gets constructed
In derived Classes the Base always gets initilized first
Hope I am doing better and thankx
|
|
|
|
|
Hi
I have an Object/Class derived from Cevent I would some how like to instantiate it
well actually make a global copy of it via the new operator on the Heap available For
the entire app
I know using the static keyword I can acoomplish this
e.g .static Myevent Myevent1; however using the new operator presents a problem
So....
I ended up allocating the storage required on the Heap
myeventptr = HeapAlloc(GetProcessHeap(),0,sizeof(MyEvent))
and the then kicking of the constructer via myeventptr->MyEvent::MyEvent(....);
is this going to create the object for me ???
thankx
|
|
|
|
|
What about the singleton pattern [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
ForNow wrote: I ended up allocating the storage required on the Heap
myeventptr = HeapAlloc(GetProcessHeap(),0,sizeof(MyEvent))
and the then kicking of the constructer via myeventptr->MyEvent::MyEvent(....);
is this going to create the object for me ???
You really don't want to do that. Pallini probably has the solution you should use but what you described is covered in C++ with Placement new[^]
As always I strongly recommend novice C++ developers not to make stuff up. There exists an enormous amount of information freely available on the internet. Use it or make up your own stuff, it's your choice.
|
|
|
|
|
thankx for that info aboutr placement that was in 10.4.11
seems like chap 10 12 and 15 are key for me to understand
thankx again
|
|
|
|
|
ForNow wrote: well actually make a global copy of it via the new operator on the Heap available For the entire app
Ummmm - why? You don't need to create a global object on the heap.
If you're just writing an app (and not a DLL), I'd do this:
(in the .h file)
Myevent& GetMyEvent();
(in the .cpp file)
Myevent& GetMyEvent()
{
static Myevent theOnlyMyevent;
return theOnlyMyevent;
}
or (if I was being a little more rigourous)
(in the .h file)
class Myevent : public CEvent
{
public:
static Myevent& GetMyEvent();
your stuff
private:
Myevent();
~Myevent();
Myevent(Myevent const&);
Myevent& operator=(Myevent const&);
);
(in the .cpp file)
Myevent& Myevent::GetMyEvent()
{
static Myevent theOnlyMyevent;
return theOnlyMyevent;
}
then you get the event object with Myevent::GetMyEvent();
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Clever!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry about the vague subject title, but I can't really think of a better way to describe it. Say I have this class:
class Foo
{
public:
Foo();
~Foo();
virtual void DoSomething(void *p)
{
if(Next)
Next->DoSomething(p);
}
Foo *Next;
};
I derive from it:
class Bar : public Foo
{
public:
Bar();
~Bar()
void DoSomething(void *p)
{
if(p)
free(p);
}
};
Say I call Bar->DoSomething((void *)0x1234). It will (hopefully) free the pointer. Is there any way to ensure that Bar does what it wants, then drops down to Foo's implementation afterwards?
|
|
|
|
|
void DoSomething(void *p)
{
Foo::DoSomething(p);
if(p)
free(p);
}
That's how you call the base class implementation.
Looking at your code one might be concerned that you are heading towards trouble. Have you read the book Effective C++, you should. Also you should be studying Design Patterns.
|
|
|
|
|
Thanks for the references, I'm ordering one ASAP. I'm aware that I could explicitly invoke the base class' method beforehand, I was looking for a way to make the invocation implicit, and the base class' method is invoked after the derived class' method. Something like this:
Bar::DoSomething
Foo::DoSomething
In what way am I heading towards trouble?
FWIW, I wasn't the one who univoted
modified on Saturday, April 25, 2009 10:13 AM
|
|
|
|
|
Computafreak wrote: In what way am I heading towards trouble?
The scope of that question is far to large to discuss in a forum which is why I referred you to other sources. However a quick couple of points I will provide are; 1) your notion of calling the base class method after the Bar method. Notice in my posted example the base class is called first. That is because in your posted code the Bar method frees the memory.
void DoSomething(void *p)
{
if(p)
free(p);
}
Calling the Foo method after that would result in the Foo method having an invalid pointer.
2) Also using void pointers is NOT Best Practice. Strongly Typed code is preferable.
Anyway all of these types of problems are covered in materials such as the ones I pointed you at. How do you think I know about them? I didn't invent anything you know, I learned from others. 
|
|
|
|
|
The second problem is simply a problem with my example. I was in rather a rush, so apologies for causing the misunderstanding. I hadn't thought about the first problem though. You're right; the base class' method should be called first. But is there any way to make this call implicit?
|
|
|
|
|
Computafreak wrote: But is there any way to make this call implicit?
Not sure how to respond to that. If you have to do something to make it happen then it can't be implicit can it? If they made that implicit, then you would have to do something to eliminate the base being called. It seems the current way is more obvious therefore easier to understand, yes?
|
|
|
|
|
What I mean is this. Normally, when the derived class' method is called, the base class' method is not. What I'm looking for is how to make the base' class method be called, and then the derived class' method
Example: I call Bar->DoSomething((void *)0x12345), the parameters are pushed onto the thread's stack, and Bar::DoSomething is invoked. I want the parameters to be pushed, Foo::DoSomething to be called (the base class) and then Bar::DoSomething to be called (the derived class) automatically
If it helps, a little background. I have a Stream base class. It has a LinkedStream property, which refers to a Stream pointer. When I call Stream::Write, I want to call LinkedStream->Write beforehand, then pass the arguments to the derived class' write method
|
|
|
|
|
Computafreak wrote: I want the parameters to be pushed, Foo::DoSomething to be called (the base class) and then Bar::DoSomething to be called (the derived class) automatically
Then write your own language and compiler that will do that I guess. I terms of C++ it's like you are saying you want up to be down. That's just to bad for you because it isn't, period.
However I would also point out that it seems you are making a big deal out of nothing. In your background explanation with streams, if your derived class just calls the base first it results in the runtime behavior you describe.
|
|
|
|
|
I see now. Thanks for the explanation. I'm definitely not going to be writing my own compiler, but I see how my request wasn't in the best of understanding. You've been very helpful; thanks again
|
|
|
|
|
Hi,
I've got a few extensions I need to add to the registry so when the user is exploring via windows explorer they will see a default icon I've created for the extensions. I've already created a script to register the 'display description' (ie: '.htm' file extensions are described with 'HTML Document'). That, I have working.
What keys do I need to create in order for an icon to be displayed for the file. (By default, the 'Unknown Document' is shown.) I want to display my own icon. All the sites I've explored during my research only mention how to change existing registry entries.
I need a .reg file because the app is going to be deployed.
Will I need to create a CLSID or use one from the App that has been created? I'm thinking I'm going to need 2 or 3 registry entries in order to get this to work but I don't know where to start.
Anyone help? Thanks! 
|
|
|
|
|
Like2Byte wrote: but I don't know where to start.
Like2Byte wrote: Anyone help?
Sure I always enjoy helping the Google impaired. Knock yourself out[^]
|
|
|
|
|
I get the previously said error when i build in the following combination
Pockect PC 2003 ;
Win32 (Win CE Emulator debug or Release) ;
Pocket PC 2003 device;
but when i chage the configuration to the following
Pockect PC 2003 ;
Win32 (Win CE Arm debug or Release) ;
Pocket PC 2003 device;
I get the following error :
winscard.lib(WINSCARD.dll) : fatal error LNK1112: module machine type 'THUMB' conflicts with target machine type 'ARM'
Any clue why this happens ?
Thanks !
|
|
|
|