- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've encountered something strange when calling a parent's method inside a constructor. If the class and the parent are templates, I get "error: identifier "go" is undefined" message. A minimal code example (tested with "icc (ICC) 14.0.1 20131008"):
template<typename T> struct boom { void go() {} }; template<typename T> struct boom2 : public boom<T> { boom2() { go(); } }; boom2<int> aaa;
Without the templates, it works. It can also be fixed by replacing go() with this->go(), so it is not a big issue for me. But it makes me wonder, whether my code is correct. As far as I know, it should be, but I'm not really familiar with all the details of the C++ standard.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your code is incorrect. Since you are using a dependent base class and you are using the name is an unqualified way the name will not be found.
See:
http://eli.thegreenplace.net/2012/02/06/dependent-name-lookup-for-c-templates/
http://womble.decadent.org.uk/c++/template-faq.html#base-lookup
Judy
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've just noticed that the problem is not limited to calls from constructor, but from any method. Seems like I may doing something in a fundamentally wrong way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your code is incorrect. Since you are using a dependent base class and you are using the name is an unqualified way the name will not be found.
See:
http://eli.thegreenplace.net/2012/02/06/dependent-name-lookup-for-c-templates/
http://womble.decadent.org.uk/c++/template-faq.html#base-lookup
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great! Thanks a lot for the explanation. So the code is indeed incorrect and the fix is correct. As I already wrote, I'm not really familiar with such details of C++, but the links explain it well.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page