how to use C++ with classes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: how to use C++ with classes

Post by sebihepp »

Yes, I have read this article albeva.
And I have implemented my own version of this function.
But why does my kernel calls this function?
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: how to use C++ with classes

Post by sebihepp »

Can't anyone help me? I only need to know why my VirtualFunctionHandler is always called although
there is no virtual function. If it helps I can upload my project into a webspace and write down a link here.

Sebihepp
albeva
Member
Member
Posts: 42
Joined: Thu Aug 21, 2008 8:31 pm

Re: how to use C++ with classes

Post by albeva »

Read the article again then:
Why?

It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called.
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: how to use C++ with classes

Post by sebihepp »

Sorry, I must be blind. Or it is because my native language is german.
"It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called. "
I always thought, if the compiler cannot call a virtual function, it will report an error?
And just when the instruction "call _main" is executed, this function mentioned above is
called instead.

I use C instead of C++ now, but the source of this error interests me. So if anyone have time to help
me, he is welcome.

Greetings Sebihepp
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Re: how to use C++ with classes

Post by madeofstaples »

albeva wrote:Read the article again then:
Why?

It is a requirement of C++ to provide a backup function to call when a virtual function cannot be called.
But sebihepp's question was not just "why", it was "why is my virtual function handler always called??" and just below the text you quoted, the article continues:
If during runtime your kernel detects that a call to a pure virtual function couldn't be made, it calls the above functions. These functions should actually never be called, because without hacks (or through undefined behaviour of your kernel) it is not possible to instantiate a class that doesn't define all pure virtual functions. But nonetheless you have to define these functions or your linker will complain about unresolved symbols.
So either I'm confused, or the actual answer to sebihepp is that he has overwritten the virtual function table of his object... ?
Some people are offended by the verifiable truth; such people tend to remain blissfully unencumbered by fact.
If you are one of these people, my posts may cause considerable discomfort. Read at your own risk.
sebihepp
Member
Member
Posts: 195
Joined: Tue Aug 26, 2008 11:24 am
GitHub: https://github.com/sebihepp

Re: how to use C++ with classes

Post by sebihepp »

@madeofstaples:
Yes, I am thinking that too. But I have no objects!!! :shock:
I have only a main function with a "while (1);" in it.

Sebihepp
albeva
Member
Member
Posts: 42
Joined: Thu Aug 21, 2008 8:31 pm

Re: how to use C++ with classes

Post by albeva »

see assembly output. It might be some gcc internal stuff. Where it would want to get the address of this function...
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Re: how to use C++ with classes

Post by codemastersnake »

Combuster wrote:In the category required knowledge:

USE A C++ COMPILER AND NOT A C COMPILER.

I seriously doubt you should be developing an OS when you even failed to reach "hello world" level :shock:
Don't discourage anybody! [-X
Post Reply