|
I guess he missed out B deriving from A by mistake. That apart, I don't see why the type of the class needs to be known. That's what virtual functions are for, aren't they?
And he had casted it to Base *. (I found out by looking at the HTML source).
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
I guess he missed out B deriving from A by mistake
That was my guess also but then it is exactly the same that I explained
S. Senthil Kumar wrote:
That apart, I don't see why the type of the class needs to be known. That's what virtual functions are for, aren't they?
Yes when you call the function from outside the class with a pointer. Here what he wants to do is call a function from the base class (that just exist in the base class) then call from within this function the derived function Foo. But from within the class, if you call it directly, you will call the function from the base class and not from the derived class (not using the virtual table). So to make it work you need to cast the this pointer into the child class thus it has to be known ! Maybe the missing part in the code was that I tried to cast into the base class but that won,t work neither...
|
|
|
|
|
No, it doesn't matter whether you're calling the virtual function from outside the class or inside. As long as you're using a pointer to the class, you should be fine. If you call it from within the base class, the call will get translated to this->Func(); which is the same as p->Func() where p is a pointer to Base.
class Base
{
public:
virtual void Stop() = 0;
void SomeFunc()
{
Stop();
}
};
class Derived : public Base
{
public:
void Stop()
{
cout << "Derived" ;
}
};
int main()
{
Base * b = new Derived();
b->SomeFunc();
}
This piece of code prints Derived as expected.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Just watch out during construction and destruction when the vtable is changing all the time.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
My guess is you haven't overridden the virtual function correctly. Maybe it has fewer or more parameters than the original function, maybe it's misspelled. Also, I don't really see why you should be using a static_cast to call a virtual function.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
My guess is you haven't overridden the virtual function correctly
If that would be the case, than the compiler would complain about instantiating abstract classes, since not all abstract functions have been implemented...
S. Senthil Kumar wrote:
Also, I don't really see why you should be using a static_cast to call a virtual function.
This would be, because the compiler complains about unresolved external symbols if I omit that. I thought that this should invoke a virtual function call using a pointer from the v-table, but something is terribly wrong and I don't know what.
I also got the blogging virus..[^]
|
|
|
|
|
Yeah, you're right. Can you post the full code? Maybe that'll help.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The simplified code of the base class
<br />
template <class T><br />
class IMultiThreaded : protected A, public B<T>, public C, public D<br />
{<br />
public:<br />
virtual ~CBase();<br />
<br />
vitual DWORD Stop(DWORD* pdwCode, DWORD dwWaitTimeOut = DEFAULT_TIMEOUT) = 0;<br />
};<br />
<br />
template <class T><br />
CBase<T>::~CBase()<br />
{<br />
if( m_bSomeConstant ) Stop(NULL); <br />
}<br />
The code of the derived class:
<br />
<class><br />
template <class T><br />
class CDerived : public CBase<T><br />
{<br />
public:<br />
virtual ~CDerived() { }<br />
virtual DWORD Stop(DWORD* pdwCode, DWORD dwWaitTimeOut = DEFAULT_TIMEOUT);<br />
}<br />
<br />
template <class T><br />
DWORD CDerived<T>::Stop(DWORD *pdwCode, DWORD dwWaitTimeOut)<br />
{<br />
}<br />
I also got the blogging virus..[^]
|
|
|
|
|
It looks like you are calling the virtual function from the destructor. That's a big no-no.
The order of destructor execution in C++ is such that by the time you're in the destructor of your base class, the derived part of your instance is already gone. The compiler is intelligent enough to figure that out and decides to call the base class function itself. In your case, it is pure virtual and so you are getting the unresolved external symbol error.
If you static cast it to Base explicitly, I guess the compiler assumes you know what you are doing and calls the virtual function anyway. But at runtime, it'll blow up badly.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Just make the destructor virtual. That should solve your problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
As you can see in my code example, the destructor is alreay virtual. As you explained in your previous post, the function of the derived class won't be called, since the derived part is destroyed already...
[EDIT]
I already solved the problem, by putting the cleanup in a special cleanup routine, that the user has to call from the derived class's destructor. I would have loved a more nice solution, but I guess that's not going to happen..
[/EDIT]
I also got the blogging virus..[^]
|
|
|
|
|
struct
__declspec(uuid("F5748778-4F2F-4dd7-AB08-2616D76A1DA4"))// //why?
mystruct
{
...
};
|
|
|
|
|
HeartFriend wrote:
struct
__declspec(uuid("F5748778-4F2F-4dd7-AB08-2616D76A1DA4"))// //why?
mystruct
{
...
};
Are you reading any Com header file!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
u can say that, it's a snippet i get from our project written by other developer
|
|
|
|
|
For Uniquly Defined the Com Interface!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
HI all !
SO I'm discovering Visual studio C++, because I'm trying to put some C code in a GUI
what i'm trying to do: in a window the user set some parameters, these parameters mare needed by the C program.
the problem: I don't how to transfer the C code in the visual C++ code (don't know if i must create a new class ...)
If someone have some infos or tuto to do that kind of thing, i will be grateful !!!
|
|
|
|
|
I'm not quite clear on exactly what you are after. I understand that you are creating a GUI-based Windows application in C. Is that much correct? You want to display a window, most likely a dialog box, such that the user can enter some data. Right so far? From here is where your requirements get fuzzy.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes you're right, the user will enter some parameters which are use for the program in C (it's a population growth simulator) after the run of the program the user can choose to have a visualization of th distribution of the ppulation
|
|
|
|
|
I suspect the function you are looking for is GetWindowText() . Assuming you are using an edit control, it copies the text of the control into the buffer.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
ok thx!
But what I'm looking for at first (I'm reallya noob) is to put the C code in a mfc application for example .
|
|
|
|
|
Now you've really lost me. What C code are you referring to? Have you already created the MFC application? Is it an SDI, MDI, or dialog-based application? Have you created the dialog template that will be used to accept the user's information? Do you have a CDialog -derived class for this template?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Sorry!
In fact I would like to have the general lines to create a MFC application where user set parameter for a code IN Clanguage( also how to integrate the code to a MFC application) and also have in the MFC application the possibility to view some graphics which are the results of the execution of the C code.
I hope It's clear, I'm sorry my english is quiet bad ...
|
|
|
|
|
guillaume.dauphin wrote:
I hope It's clear, I'm sorry my english is quiet bad
I can read your Enlish just fine. It's what you are trying to accomplish that's throwing me.
It sounds like you need to use AppWizard to create an MFC application. Once you have that done, we can then proceed to the next step.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I've visual studio .net 2003 so there is no appwizard but I know (and I do it) how to create MFC applications, it's the way to call my program in c (to put in the MFC appli) that I don't know...
I'm sorry I won't reply before Tomorrow
Thx for your help
|
|
|
|