You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hello,
Following program can not be compiled by g++ (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609:
--[beg]--[main.cpp]--
#include <iostream>
class A { public:
void bar(int value) {
std::cout << "bar:" << value << std::endl;
}
void foo(int value) {
std::cout << "foo:" << value << std::endl;
}
};
class B : public A { public:
void foo() {
std::cout << "void" << std::endl;
}
};
int main(void)
{
B b;
int i = 1234;
b.foo();
b.bar(i);
b.foo(i); /* Error is here -> to avoid error 'b.A::foo(i)' has to be called */
return 0;
}
--[end]--[main.cpp]--
# g++ main.cpp
main.cpp: In function ‘int main()’:
main.cpp:29:10: error: no matching function for call to ‘B::foo(int&)’
b.foo(i); /* Error is here -> to avoid error b.A::foo(i) has to be called */
^
main.cpp:14:8: note: candidate: void B::foo()
void foo() {
^
main.cpp:14:8: note: candidate expects 0 arguments, 1 provided
I don't see any conflicts.
'bar' function implementation is found correctly in A.
Why compiler is not able to find automatically 'foo(int)' implementation in A?
Regards
--
Maciej Labanowicz
Paavo Helde
unread,
Aug 8, 2018, 9:24:02 AM8/8/18
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
foo in b is hiding inherited foo from A. This is a safety feature to
make the code more robust against later changes.
To unhide A::foo, add the following line into B:
using A::foo;
chris...@engineer.com
unread,
Aug 9, 2018, 8:32:26 PM8/9/18
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message