// forward declaration in one header file.
class FloatImage;
// Definition in another header file.
template<typename T> class CudaImage {
};
using FloatImage = CudaImage<float>;
// forward declaration in one header file.
template<typename T> class CudaImage;
using FloatImage = CudaImage<float>;
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/975ab4cd-2ff0-4a09-9fac-7c37dc67cf16%40isocpp.org.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/975ab4cd-2ff0-4a09-9fac-7c37dc67cf16%40isocpp.org.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPuuy5cZ8ak8M%3DujRtqgjSXoPh4%2BOt4eALaoy69hU8ZJ-EFtCQ%40mail.gmail.com.
A forward declaration of a class name is currently not allowed to be resolved by a type alias of a class template. I don't see the logic to this, why is this illegal:
// forward declaration in one header file.
class FloatImage;
// Definition in another header file.
template<typename T> class CudaImage {
};
using FloatImage = CudaImage<float>;
A forward declaration of a class name is currently not allowed to be resolved by a type alias of a class template. I don't see the logic to this, why is this illegal:
// forward declaration in one header file.
class FloatImage;
// Definition in another header file.
template<typename T> class CudaImage {
};
using FloatImage = CudaImage<float>;
Godbolt: https://godbolt.org/g/mmTTeQ shows that all compilers reject this.This has created a fair amount of trouble for me when trying to refactor what was previously a FloatImage class to a generic pixel type template. I don't see the logic to making thisillegal as FloatImage is still the name of a class, i.e. an instance of the CudaImage class template.
While I can update the forward declaration to:
// forward declaration in one header file.
template<typename T> class CudaImage;
using FloatImage = CudaImage<float>;
This seems to be an unnecessary leakage of implementation detail.
so is there a technical reason preventing this from being allowed or is it just an oversight that could be corrected?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org.
I am wondering if your motivation is an XY problem, please see inline.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b2fb570b-aadb-423e-9821-025cb447cf60%40isocpp.org.
I got one good answer: it is not possible due to name mangling having to know that FloatImage will resolve to a template instance. I used the proposed solution but it unfortunately had me change the forward declarations of FloatImage.
On Saturday, June 30, 2018 at 9:49:52 AM UTC+3, Bengt Gustafsson wrote:I got one good answer: it is not possible due to name mangling having to know that FloatImage will resolve to a template instance. I used the proposed solution but it unfortunately had me change the forward declarations of FloatImage.What solution did you use?
Did you try the concrete class solution - it is not as naïve as it sounds, not as hard as it sounds (in C++11+) and has many protentional side benefits.
Otherwise the classical solution is not to forward declare a class but to have xxxfrw.h header instead, where you can put all "leakage of implementation detail".
In my previous response I acknowedged the explanation that this has to do with name mangling, where ultimately the class name would be mangled according to its real identity, i.e. CudaImage<float> and thus that a forward declaration "class FloatImage;" would be natural to reject.
However, on second thought, FloatImage just as any class name is not an entity in itself that is known to the linker. And as you can't call methods on a class without seeing its full definition there is no risk that references to erroneously mangled method names sneak in to an object module compiled only seeing the forward declaration, right?
void func(const FloatImage &);
using fptr = void(*)(const FloatImage&);
fptr f = func;
With this in mind, is there a technical reason thatmy initial construct must be forbidden? I don't see that Nicol's explanation holds "FloatImage turns out eventually to be a type alias and not a class". But the very reason for having a type alias is to give a class another name, so why can't it be forward declared under this alternate name?