Hi!
I was trying to find the solution to this problem, but I don't think I
could quite come up with the correct keywords to find it, since I'm
pretty sure it's been asked before. In short, here's the situation
(ignore missing namespaces, etc, since I'm not cut-pasting this..)
// a.h
template <class B>
class A
{
...
public:
template <typename Argument>
inline A & operator<<(Argument arg);
...
};
#include "a.inl"
// a.inl
template <class B>
template <typename Argument>
inline A<B> & A<B>::operator<<(Argument arg)
{
...
}
template <class B>
template <>
inline A<B> & A<B>::operator<<(Control ctl)
{
...
}
// End
Now, the problem is that my compiler (G++32) is giving me an error
'enclosing class templates are not explicitly specialized.' Now, the
question is, obviously, is there something wrong with my syntax (does
the specialization need to come first, etc), or should I get another
compiler? I've tried a couple of tricks and there're obvious
workarounds but I'd rather do it this way and in any case I'd feel
better knowing the correct syntax if such exists. Help appreciated.
E 2 6229 go**********@elvendesigns.com (Elven) wrote in
<91*************************@posting.google.com> : Hi!
I was trying to find the solution to this problem, but I don't think I could quite come up with the correct keywords to find it, since I'm pretty sure it's been asked before. In short, here's the situation (ignore missing namespaces, etc, since I'm not cut-pasting this..)
// a.h
template <class B> class A { ... public: template <typename Argument> inline A & operator<<(Argument arg);
inline is redundant here.
... };
#include "a.inl"
// a.inl
template <class B> template <typename Argument> inline A<B> & A<B>::operator<<(Argument arg) { ... }
template <class B> template <>
template <> is misleading here.
inline A<B> & A<B>::operator<<(Control ctl) { ... }
A<B>& A<B>::operator <<(Control ctl) is not
specialization of member function template, it is a member function
of template class A<B> .
It needs to be declared in the template class as a member function. // End
Now, the problem is that my compiler (G++32) is giving me an error 'enclosing class templates are not explicitly specialized.' Now, the question is, obviously, is there something wrong with my syntax (does the specialization need to come first, etc), or should I get another compiler? I've tried a couple of tricks and there're obvious workarounds but I'd rather do it this way and in any case I'd feel better knowing the correct syntax if such exists. Help appreciated.
E
I have hard time to match the error reported to the cause but maybe
it means exactly it.
Hope it helps.
grzegorz
On 10 Aug 2003 12:47:31 -0700, go**********@elvendesigns.com (Elven)
wrote: Hi!
I was trying to find the solution to this problem, but I don't think I could quite come up with the correct keywords to find it, since I'm pretty sure it's been asked before. In short, here's the situation (ignore missing namespaces, etc, since I'm not cut-pasting this..)
// a.h
template <class B> class A { ... public: template <typename Argument> inline A & operator<<(Argument arg); ... };
#include "a.inl"
// a.inl
template <class B> template <typename Argument> inline A<B> & A<B>::operator<<(Argument arg) { ... }
template <class B> template <> inline A<B> & A<B>::operator<<(Control ctl)
That should be:
template <class B>
template <>
inline A<B> & A<B>::operator<< <Control>(Control ctl)
but you can't specialize a member without fully specializing the
enclosing template, since that would give the compiler some confusion
over which specialization to use. e.g. add
template <>
template <class Argument>
inline A<char>& A<char>::operator<<(Argument arg)
Now what does the compiler use for A<char>::operator<<(Control)?
Now, the problem is that my compiler (G++32) is giving me an error 'enclosing class templates are not explicitly specialized.' Now, the question is, obviously, is there something wrong with my syntax (does the specialization need to come first, etc), or should I get another compiler? I've tried a couple of tricks and there're obvious workarounds but I'd rather do it this way and in any case I'd feel better knowing the correct syntax if such exists. Help appreciated.
The way to do it is this, using a non-member and partial
specialization:
template <class B, typename Argument>
struct stream_impl
{
static void impl(A<B>& a, Argument const& arg)
{
//default impl
}
};
//non-member operator.
template<class B, typename Argument>
inline A<B>& operator<<(A<B>& a, Argument const& arg)
{
impl(a, arg);
return a;
}
Then you can specialise using:
template <class B>
struct stream_impl<B, Control>
{
static void impl(A<B>& a, Control const& arg)
{
//special impl
}
};
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeff |
last post by:
/* --------------------------------------------------------------------------
Hello,
I was experimenting with class templates and specializing member
functions and came across a simple problem...
|
by: Dmitry Epstein |
last post by:
Here is an example of a problem, which I tried to reduce to its
bare essentials:
// begin test1.cpp
class E {
public:
template<class T> static void f();
};
template<class T> void E::f() {}
|
by: nikola |
last post by:
Hi all,
I was working with a simple function template to find the min of two values.
But since I would like the two values to be different (type) I dont know
what kind of value (type) it will...
|
by: Walt Karas |
last post by:
The following gives an error in the declaration of the
member function x() of the class template Tpl, compiliing
with a recent version of GCC under Solaris:
class A { };
class B { };
...
|
by: Imre |
last post by:
Let's suppose we have a primary template with one argument defined in a
header file. Two source files include this header, and both define a
specialization of the primary template. Later, both...
|
by: Imre |
last post by:
Hi
I'm looking for a way to make sure that whenever a new instance of a
class template A is created, then an instance of class template B is
also created, with the same template parameters. Of...
|
by: stinos |
last post by:
Hi All!
suppose a class having a function for outputting data somehow,
class X
{
template< class tType >
void Output( const tType& arg )
{
//default ToString handles integers/doubles
|
by: Rahul |
last post by:
Hi,
Is there a way to partially specialize only a member function of a
template class (not the whole class).
e.g.
template <typename A, typename B>
class Base
{
public:
|
by: (2b|!2b)==? |
last post by:
I would like to know if I can specialize only a specific method for a
class template.
Is the (specialization) code below valid?
template <typename T1, typename T2>
class MyClass
{
public:
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |