Original Post
🔒 Locked
Forward class declarations
Advertisement
yes you can DECLARE a class, and almost anything else which isn''t a definition, an infinite amount of times ...
also ... be carefull with forward declaring inside a namespace, that you are actually doing what you mean to do ... ie - make sure that the item in question belongs IN the namespace ...
which also means ... do not include header files within a namespace, unless you mean to wrap it up into a namespace.
ALSO important ... if you have something like a static member (class member ... not C style static) which is in a class, in a namespace ... then it''s definition must be inside that namespace as well ... which made for some REALLY weird code with a template library I wrote once ...
I had a templated class, with a static member ... inside a namespace (lets all it A). Then I specialized this template inside other libraries over particular types, and those types we''re in a namespace (we''ll call it B).
So inside each .cpp file for each of these derived types, I had a situation where I had to do basically this:
also ... be carefull with forward declaring inside a namespace, that you are actually doing what you mean to do ... ie - make sure that the item in question belongs IN the namespace ...
which also means ... do not include header files within a namespace, unless you mean to wrap it up into a namespace.
ALSO important ... if you have something like a static member (class member ... not C style static) which is in a class, in a namespace ... then it''s definition must be inside that namespace as well ... which made for some REALLY weird code with a template library I wrote once ...
I had a templated class, with a static member ... inside a namespace (lets all it A). Then I specialized this template inside other libraries over particular types, and those types we''re in a namespace (we''ll call it B).
So inside each .cpp file for each of these derived types, I had a situation where I had to do basically this:
#include "SomeClassHeader.h"
namespace A
{
template<>
... // specialization line, cannot remember offhand
}
namespace B
{
// actual class function implementation}
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement