|
Most likely you are, indirectly, calling a pure virtual function in your base class constructor.
I recently wrote up how the compiler handles abstract classes and the C++ rules for which overrides are called at what point in answer to a question here[^].
Basically what's happening is you're trying to call through a virtual function that was declared pure either in your class or one of your base classes.
One possibility:
class A
{
public:
A();
protected:
void OtherFunc();
virtual void MyFunc() = 0;
};
class B : public A
{
public:
B();
virtual void MyFunc();
};
A::A()
{
OtherFunc();
}
void A::OtherFunc()
{
MyFunc();
}
B::B()
{
}
void B::MyFunc()
{
} When A's constructor body runs, the virtual function pointer is still pointing to A's vtable. The constructor calls OtherFunc which calls MyFunc , which is generated as a virtual call through the vtable. However, A::MyFunc is a pure virtual function; calling it this way is an error. The Visual C++ compiler traps the error by making the vtable slot point to a routine in the runtime library which reports the error.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
No , i have already mentioned. i am not calling it through constructor.
Any other reason?
anyways, thanks
Shoaib
|
|
|
|
|
I've never experienced a pure virtual function call. However from what I hear it really can only happen in the constructor or in the deconstructor. Then off course it could be a side effect of using invalid pointers to these objects. Also MSVC6 has been known to allow abstract classes to be created in certain cases. It also never hurts to do a rebuild all. I’ve seen some really straight up weird occurrences cause me a good couple hours of confusion all completely melt with a simple rebuild all.
|
|
|
|
|
I have been trying to use the http://www.beyondlogic.org/porttalk/porttalk.htm[^]">PortTalk device driver to access the parallel ports of my PC.
The sample Console applications works OK, but when I try and use this code in a MFC application I get the following errors:-
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2065: 'SC_HANDLE' : undeclared identifier
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2146: syntax error : missing ';' before identifier 'SchSCManager'
c:\ParallelPortTest\ParallelPortTest\pt_ioctl.c(114): error C2065: 'SchSCManager' : undeclared identifier
I have tried many complier options but still get the above errors, any suggestions?
|
|
|
|
|
Check the include files and the defines (maybe version conflict, MFC assumes windows NT 4.0 -> stdafx.h ).
Don't try it, just do it!
|
|
|
|
|
Running Windows 2000 SP3 and have included stdafx.h, still lots of errors.
|
|
|
|
|
|
Thanks, I included #include winsvc.h in the file that was giving the errors.
BUT now get the following Link Erros:-
ParallelPortTest error LNK2005: "void __cdecl outportb(unsigned short,unsigned char)" (?outportb@@YAXGE@Z) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "unsigned char __cdecl inportb(unsigned short)" (?inportb@@YAEG@Z) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "unsigned char __cdecl OpenPortTalk(void)" (?OpenPortTalk@@YAEXZ) already defined in ParallelPortTest.obj
ParallelPortTest error LNK2005: "void __cdecl ClosePortTalk(void)" (?ClosePortTalk@@YAXXZ) already defined in ParallelPortTest.obj
Do you know what libraries to include?
|
|
|
|
|
Hey everybody!
I created 2 function.
<br />
void CHelperDlg::UpdateVars(void)
{<br />
CFile fLinkAfter(m_strAppPath+"\\Settings\\LinkAfter.dat", CFile::modeReadWrite);<br />
<br />
ReadFiles(m_clsOptions.m_OptionLinkAfter, fLinkAfter);<br />
MessageBox(m_clsOptions.m_strOptionLinkAfter);<br />
}<br />
<br />
void CHelperDlg::ReadFiles(CString TheVar, CFile ReadedFile)<br />
{<br />
char cBuffer[10];<br />
UINT iRead;<br />
<br />
iRead = ReadedFile.Read(cBuffer, 10);<br />
TheVar = cBuf;<br />
}<br />
now, as far as I understand the var "m_clsOptions.m_OptionLinkAfter"
should get the content of the cBuf, and for some reason, the
"m_clsOptions.m_OptionLinkAfter" still remains empty after the other function is called (checked with the MessageBox).
(TheVar gets m_clsOptions.m_strOptionLinkAfter as its parameter)
shouldn't the ReadFiles function update m_clsOptions.m_strOptionLinkAfter???
THANKS!!!
|
|
|
|
|
Green Fuze wrote:
void CHelperDlg::ReadFiles(CString TheVar, CFile ReadedFile)
Change to:
void CHelperDlg::ReadFiles(CString &TheVar, CFile ReadedFile)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Perfect!
and I think I just understood something really important!
thanks!
|
|
|
|
|
On top of that, make sure you pass your CFile object by reference or pointer, otherwise the state of the CFile object when returning from the function will be out of sync with the state of the operating system file handle.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Do anyone know how to encrypt a data into a database in vc++?plz help me!!!
|
|
|
|
|
What do you want to know? The encrypt method, or the encripting with vc++? You can google and find encrypt method.
<italic>Work hard, Work effectively and a bit of luck is the key to success.
|
|
|
|
|
|
Hi,
I am trying to delete a value from my windows registry through VC++ code. Tried using a couple of win API's like RegDeleteValue(), DelRegTree but did'nt really work.
May be I am passing incorrect arguments or I am using the wrong functions. I would appreciate if someone shares his/her views, may be the method to be used or so.
eg.
I have to delete XXX from the registry. This is how my registry looks.
HKEY_CURRENT_USER
Software
Something
ProductV1
ProductV2
XXX
Thanks
|
|
|
|
|
Here is small Source code
#include <atlbase.h>
CRegKey key;
if(key.Open(HKEY_CURRENT_USER,"Software\\Something\\ProductV1\\ProductV2")==ERROR_SUCCEESS)
{
key.DeleteValue("XXX");
key.DeleteSubKey("123");
key.Close();
}
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
Something has badly changed in .NET compared to vc 6.
I am getting an error
error C2065: 'CRegKey' : undeclared identifier
But I looked at .NET\atlbase.h, I see a class named CRegKey.
Anybody any ideas?
Thanks
|
|
|
|
|
It's going to be hard to show what you did wrong if you don't show us the code that is not working.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I copied and pasted the same code that Alok listed above.
Also included the header file #include <atlbase.h> in the source code. Thats all I did.
Thanks
|
|
|
|
|
Ok, but what about the code that you had before CRegKey was suggested? There is no reason why you should not be able to get that working.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I had tried this earlier. But RegDeleteValue always returns 2 (file not found error)
long retVal = RegDeleteValue(HKEY_CURRENT_USER, "Software\\Company Name\\Product Name\\File-TT");
Thanks
|
|
|
|
|
Maybe for this one you need to use:
HKEY MyKey;<br />
<br />
LONG RegOpenKey(<br />
HKEY_CURRENT_USER, "Software\\Company Name\\Product Name,<br />
&MyKey<br />
);<br />
<br />
RegDeleteKey( <br />
MyKey, <br />
"File-TT"<br />
);<br />
<br />
RegCloseKey(MyKey);
You delete registry values by opening the entire key, you delete registry keys by opening the parent key and then calling RegDeleteKey with the name of the child.
|
|
|
|
|
Hi All,
I want to write a simple C/C++ program which should be able to display All Unicode characters, that are present in character set of any Standard Unicode Font.
I am using the wchar_t data type to store the character constant but how can i pass the Unicode value for a literal like HINDI Aa (\u0905)
But it will always give the error literal constant extends limit
Can Anyone help me out
Thanks In Advance
Nitin Mahajan
|
|
|
|
|