Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

any difference between "virtual void IBase::Foo" and "virtual void Foo"?

Tags:

c++

visual-c++

I've used VisualAssistX Implement Virtual Methods option and it generated:

class Base: public IBase
{
public:
    Base(void);
    ~Base(void);
    virtual void IBase::Foo();

I've noticed that I can omit IBase and program still compiles like that:

    virtual void Foo();

If this is the same code? Why VisualAssistX inserts IBase::? Is it just kind of "code-style" to improve readability?

Thanks

like image 416
Oleg Vazhnev Avatar asked Oct 05 '22 17:10

Oleg Vazhnev


2 Answers

This would help resolve the ambiguity if you were to derive from multiple base classes with clashing virtual functions. I suspect this is the reason why VisualAssistX is choosing to insert the IBase::.

Whether IBase:: helps improve readability is debatable. I personally find it distracting.

Furthermore, the syntax is not even standard C++. See Distinct implementations for pure virtual functions with same name for a discussion and for a suggestion how the multiple inheritance problem can be solved using standard, portable C++.

like image 75
NPE Avatar answered Oct 10 '22 04:10

NPE


Definitely not improving readability, the other way around. The scope prefix is for use from outside or when there can be resolution ambiguity, using the prefix inside the scope itself just obfuscates the code and actually contradicts OOP principles. When inside scope your entity doesn't need to indicate it again, it's completely redundant. Regarding the VA I can only speculate that it was simpler for implementation.

like image 43
SomeWittyUsername Avatar answered Oct 10 '22 03:10

SomeWittyUsername