tags:

views:

194

answers:

4

What is a pseudo-virtual function in C++?

+4  A: 

AFAIK it's not a term that appears anywhere with an official definition.

Perhaps someone is talking about simulated dynamic binding?

Edit: a swift web search suggests that someone might have implemented their own dynamic polymorphism, so they perhaps have their own vtables. "Pseudo-virtual" functions would then be functions accessed through their mechanism, rather than actually being virtual functions as their C++ compiler understands them.

One reason to do this would be to implement multi-dispatch.

Do you have any context you can point us at?

Steve Jessop
Yes, it seems to be something related to simulated dynamic binding. The context is a mechanism to optimize multithreaded animation and mesh morpher systems on a 3d engine, so it makes sense. Thanks a lot.
Seth Illgard
A: 

A virtual function with a declaration.

class Foo
{
    int* bar;

    Foo() : bar(0) { bar = new int; }
    virtual ~Foo() { delete bar; }
}

This has a pseudo-virtual destructor, since it does something in the declaration. Here is a pure virtual declaration:

class Foo
{
    Foo() { }
    virtual ~Foo()=0;
}

At least, this is how I learned it.

Hooked
Yes, I remembered that and edited it in there.
Hooked
You probably mean a **definition**. Anything that can be used has a declaration. Also, pure virtual functions can also be defined.
Dr_Asik
I'm sorry, I always forget that the terms used in describing a programming language must be entirely unambiguous. Sorry, I have no formal training (yet?).
Hooked
If that's how you learned it, then whoever taught you did not understand what "pseudo" means.
Rob Kennedy
+1  A: 

I have heard the term to used to refer to multimethods (in C++ these are usually implemented using an array of function pointers where the selector offset determined by the code at runtime):

(*multiMethod[ index ])()

The multiMethod array is just an array of function pointers.

Godeke
+2  A: 

I've never heard this term. I'd guess they're either talking about the Non-Virtual Interface idiom (NVI) or they're talking about building a dispatch table of function pointers which is how one might implement polymorphism/virtual functions in C (and in fact is how C++ compilers do it behind the scenes).

Michael Burr
NVI is the first thing that came to my mind when I read the question....
Dan