Possible Duplicate:
Pointer vs. Reference
I am wondering if there any benefits in using references instead of pointers on some interface. Being more specific let's consider small example:
struct MyInterface {
virtual ~MyInterface() {}
virtual void f() = 0;
};
class MyClass : public MyInterface
{
virtual void f()
{
std::cout << "F()" << std::endl;
}
};
void myFunction(MyInterface& obj);
int main(int argc, char *argv[])
{
MyInterface* pObj = new MyClass;
myFunction(*pObj);
delete pObj;
getchar();
return 0;
}
void myFunction(MyInterface& obj)
{
obj.f();
}
In myFunction instance of MyClass can be passed as a pointer, what is written in many books. My question is what can be considered as a good practice (pointer or reference) and what is more efficient?
Sorry if this question somehow was asked previously.