Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7929 Discussions

explicit override of the virtual methods

empty_void
Beginner
539 Views
Hello.

I've found two issues with the Intel C++ Compiler 11.0.061. I believe they should be called 'bugs'.

First one, suppose we have two base classes with identically declared virtual methods, and we want to override each of them in the derived class in a different manner:
[cpp]class i_foo1
{
public:
	virtual void test() = 0;
};
class i_foo2
{
public:
	virtual void test() = 0;
};
class c_foo : public i_foo1, public i_foo2
{
	void i_foo1::test() { printf("test 1n"); };
	void i_foo2::test() { printf("test 2n"); };
};[/cpp]
Compilation succeeds, so the compiler understands this syntax (some other c++ compilers don't).
Then we call the 'test' method as follows:
[cpp]c_foo foo;
i_foo1 * ifoo1 = & foo;
i_foo2 * ifoo2 = & foo;
ifoo1->test();
ifoo2->test();
[/cpp]
But the results are rather confusing, this is the console output:
[cpp]test 1
test 1[/cpp]
After compiling source code with the Microsoft Visual C++ 2005, the results of program execution are as expected:
[cpp]test 1
test 2[/cpp]

Second issue, this one however reflects behavior ofthe Microsoft Visual C++ 2005. Suppose we have the same goals as in previous example, but now we want method to have acv-qualifier (const or volatile):
[cpp]class i_foo1
{
public:
	virtual void test() const = 0;
};
class i_foo2
{
public:
	virtual void test() const = 0;
};
class c_foo : public i_foo1, public i_foo2
{
	void i_foo1::test() const { printf("test 1n"); };
	void i_foo2::test() const { printf("test 2n"); };
};[/cpp]
This sample code generates compilation errors:
[cpp]error: declaration must correspond to a pure virtual member function in the indicated base class[/cpp]
The behavior of theMicrosoft Visual C++ 2005 is similar with one exception: if we remove 'const' qualifiers just from 'test' methods in the base classes, the compilation succeeds. Can't say for sure who's right and who's wrong in the exception situation.
But I believe, behavior of the compiler should not be restricted to the cv-unqualified methods.
0 Kudos
4 Replies
JenniferJ
Moderator
539 Views
Thanks for your post and the testcase.

I'll submit two tickets to the compiler engineers. Once there's any news, I will post here.

Jennifer

0 Kudos
JenniferJ
Moderator
539 Views
I got some information.

This explicit override feature is VC specific. We'll try to be as much compatible as possible with VC. So the 2nd issue is not a bug.

0 Kudos
empty_void
Beginner
539 Views
I got some information.

This explicit override feature is VC specific. We'll try to be as much compatible as possible with VC. So the 2nd issue is not a bug.

I'd say it's VC bug, but VC-team don't want to fix it (they've closed my feedback thread with the "Resolved(By Design)" status). I don't think bugs should be treated as features.
And I'm not sure whether it's a good idea to be a bug-compatible, but it's up to you how to treat MS extensions to the c++.
0 Kudos
JenniferJ
Moderator
539 Views
The 1st issue is fixed in the 1st 11.1 update 11.1.038. Now the output from icl should be same asvc.

Jennifer
0 Kudos
Reply