- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Trying to compile the following code:
#include <iostream> using namespace std; template<void (*F)()> void SetCallback(){ F(); } static void Foo() { struct stub_t { static void cb(){ cout << "Foo::stub_t::cb()" << endl; } }; SetCallback<&stub_t::cb>(); } void TemplateInstantiation() { Foo(); }
I get this error: "(18): error : a template argument may not reference a non-external entity".
But I can't find any restrictions on template arguments in c++11 specification, at least in draft n3376, that can explain why this is wrong.
Is there something that I have been missed? Or this is specific of the compiler?
I'm using Intel® C++ Composer XE 2015.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I take that back... Actually it looks like Microsoft has always allowed it (even before it was legal).
I have entered a defect (DPD200256284) for us to change our compiler to allow this. Thanks for reporting it.
Judy
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes it looks like this was changed between C++03 and C++11 -- see discussion here:
It looks like no compiler (including the most recent releases of Clang, GNU, Microsoft and our compiler) has implemented this change yet.
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I take that back... Actually it looks like Microsoft has always allowed it (even before it was legal).
I have entered a defect (DPD200256284) for us to change our compiler to allow this. Thanks for reporting it.
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyway (like a compiler option) to circumvent this in the meantime without a code rewrite?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page