|
Thanks for your trial, CPallini!
Any comments to my original question?
regards,
George
|
|
|
|
|
Hi,
Indeed, you didn't specify the virtual declarator to the foo function in final, but that isn't necessary since you declared it virtual in the base class. A function becomes virtual from the moment you declare it virtual to all its children.
Try the following
class Base {
public:
int foo() {cout << "Base" << endl; return 0;}
};
class Derived: public Base
{
public:
virtual int foo() {cout << "Derived" << endl;return 0;}
};
class Final: public Derived{
public:
int foo() {cout << "Final" << endl;return 0;}
};
int main()
{
Final objF;
objF.foo();
Derived* pDer = dynamic_cast<Derived*>(&objF);
if(pDer) pDer->foo();
Base* pBase = dynamic_cast<Base*>(&objF);
if(pBase) pBase->>foo();
}
The output of this will be:
Final
Final
Base
codito ergo sum
|
|
|
|
|
Thanks BadKarma,
Why the statement output Base? I think pBase is pointed an object instance whose type is Final, and the foo in Derived class in virtual, it should output Final, right?
Base* pBase = dynamic_cast<base*>(&objF);
if(pBase) pBase->foo();
regards,
George
|
|
|
|
|
George_George wrote: 2. if function is virtual, we should invoke the foo based on the type of instance pointed to, if not virtual, we should invoke the foo based on the type which is the pionter type;
Agree, and no confusion since pb is of Base type, for base foo is virtual hence the function called is through _vfptr, and _vfptr is same for both Base and Final, "Final" is the output,
u can check that by interchanging "virtual" keyword from Base to Final, in that case"since foo in Final is not final" is valid
|
|
|
|
|
Thanks Rajkumar,
Two more comments.
1.
Rajkumar R wrote: _vfptr is same for both Base and Final
What do you mean same? Suppose we create an instance of Base the content of __vfptr should be pointed to foo in Base, since foo is virtual; and if we create an instance of Final, the content of __vfptr is foo in Final, since foo is virtual declared in class Base. They are different. Why do you say they are the same.
2.
Rajkumar R wrote: since foo in Final is not final"
I do not understand the statement "since foo in Final is not final". Could you describe in more details please?
regards,
George
|
|
|
|
|
1. with _vfptr in that context i mean only one for Base * and Final * type for the instance of Final.
George_George wrote: "since foo in Final is not final".
this is the quote from your first post, I mean if the foo of final is virtual and foo of base is not virtual calling with Base type will call foo of base.
|
|
|
|
|
Thanks Rajkumar,
I doubt this. Suppose the foo in Base is not virtual and foo in Final is virtual. When we have an instance of Final, then converts to Base*, then use the Base* to invoke foo, output will be Base other than Final?
Rajkumar R wrote: I mean if the foo of final is virtual and foo of base is not virtual calling with Base type will call foo of base.
regards,
George
|
|
|
|
|
George_George wrote: I doubt this.
see this [^]
|
|
|
|
|
Great Rajkumar,
You mentioned before,
--------------------
1. with _vfptr in that context i mean only one for Base * and Final * type for the instance of Final.
--------------------
You mean if foo in Base and Final are both virtual, and if we create an instance of Final and make a Final pointer points to the instance, and also make a Base pointer points to the same instance, then pointer of type Base and pointer of type Final points to the same vtable, right?
regards,
George
|
|
|
|
|
|
Thanks Rajkumar,
My question is answered.
regards,
George
|
|
|
|
|
Hi,
I m trying to load a bitmap image(jpeg/gif) in OnPaint()..
But there s a loss of color identified(already posted qn..)
got an idea to embedd a HTML snippet into my code with ..
How to do it in a proper way??
thanks in advance..
Gita
|
|
|
|
|
Gita.Bairavi wrote: load a bitmap image(jpeg/gif) in OnPaint
try using CImage
Gita.Bairavi wrote: an idea to embedd a HTML snippet into my code with ..
to display html page and thus by showing image, u need to host html browser control, in MFC helper classes like CHtmlView, CDHtmlDialog is available
|
|
|
|
|
Did you try with CImage class it has functions that you need? and for html you can use of CDhtmlDailog.
|
|
|
|
|
Hi all.
I'm having this problem and really not getting, what is happening behind the hood. Plzz help me out in this regard.
This is basic C concept.
void main ()
{
int i = 0;
++++i;
i++++;
}
In the above code, ++++i (Pre-Increment) works but i++++ (Post-Increment) doesn't work. What could be the reason?
Plzz explain in detail.
Any Help is appreciated.
|
|
|
|
|
Because left to righ operator associativity.
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
|
|
|
|
|
Click here[^]
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Don Box wrote: i++++; //DOESN'T WORK
The second pair of "++" needs an l-value to operator on, which "i++" is not.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include<iostream>
int main()
{
int i = 0;
while(i<5)
{
std::cout << i;
i++;
}
/*
while(i<5)
{
std::cout << i;
++i;
}
*/
std::cout << std::endl;
std::cin >> i;
return 0;
}
|
|
|
|
|
Hi all
how can we select the desired sound card through directshow?
I have installed two soundcards on my PC and I want to play the audio file on one of them.
I can able to play the file on the default card like this
<br />
WCHAR wFileName[MAX_PATH];<br />
MultiByteToWideChar(CP_ACP, 0, m_szFileName, -1, wFileName,MAX_PATH);<br />
hr = m_pGraph->RenderFile((LPCWSTR)wFileName, NULL);<br />
<br />
if(FAILED(hr))<br />
return FALSE;<br />
<br />
<br />
hr = m_pControl->Run();<br />
<br />
if(FAILED(hr))<br />
return;<br />
<br />
<br />
RenderFile can play the sound on the default soundcard. I want to enumerate the devices and then select the device of my own and then play the audio.
I would have enumerated if i could know that what CLSID argument should be passed into CreateClassEnumerator because i need devices when i pass CLSID_AudioRendererCategory it gives me 6 audio renderer values
how can i configure it to 2 sound devices rather than renderers
Can anybody help me, please ?
Jabeen
|
|
|
|
|
~Jabeen~ wrote: when i pass CLSID_AudioRendererCategory it gives me 6 audio renderer values
this is because there r 2 filter instances (DirectSound And Waveout) for each audio device (
Device 1 (WaveOut, DirectSound) +
Device 2 (WaveOut, DirectSound) +
default (selected Device (Device 1/2)) (waveout, DirectSound)
= 6
)
to select a particular renderer u may need to compare the friendly names of the enumerated monikers through BindToStorage() and create the filter instance using IMoniker::BindToObject(),
the friendly names are of the format
"The DirectSound instance has the friendly name "DirectSound: DeviceName," where DeviceName is the name of the device. The WaveOut instance has the friendly name DeviceName."
~Jabeen~ wrote: how can i configure it to 2 sound devices rather than renderers
above details gives the idea for doing in directshow.
|
|
|
|
|
when you render the desired file to the sound card you must add the
sound card filter to the graph then RenderFile() method automatically
connect to that particular sound card , other wise it will connect to the
default sound card
Rajesh
|
|
|
|
|
rajeshgupta1253 wrote: you must add the
sound card filter
how to do this is the question
|
|
|
|
|
repost as previous not displayed correctly
~Jabeen~ wrote: when i pass CLSID_AudioRendererCategory it gives me 6 audio renderer values
this is because there r 2 filter instances (DirectSound And Waveout) for each audio device (
Device 1 (WaveOut, DirectSound) +
Device 2 (WaveOut, DirectSound) +
default (selected Device (Device 1/2)) (waveout, DirectSound)
= 6
)
to select a particular renderer u may need to compare the friendly names of the enumerated monikers through BindToStorage() and create the filter instance using IMoniker::BindToObject(),
the friendly names are of the format
"The DirectSound instance has the friendly name "DirectSound: DeviceName,"
where DeviceName is the name of the device.
The WaveOut instance has the friendly name DeviceName."
~Jabeen~ wrote: how can i configure it to 2 sound devices rather than renderers
above details gives the idea for doing in directshow.
or check for DRVM_MAPPER_PREFERRED_SET in waveOutMessage
|
|
|
|
|
How do I convert CString to DWORD or CString to COLORREF?
For example: CString color = "0xFF00FF"
Thanks!
|
|
|
|