Re: where is the template instance?
From: AngleWyrm (no_spam_anglewyrm_at_hotmail.com)
Date: 09/09/04
- Next message: Alwyn: "Re: Problems reversing strings"
- Previous message: Francis Glassborow: "Re: where is the template instance?"
- In reply to: Robert W Hand: "Re: where is the template instance?"
- Next in thread: Alwyn: "Re: where is the template instance?"
- Reply: Alwyn: "Re: where is the template instance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 09 Sep 2004 15:45:58 GMT
"Robert W Hand" <rwhand@NOSPAMoperamail.com> wrote in message
news:g3j0k01ocbeddhdg69hpvh50r0tne6tgna@4ax.com...
> On Thu, 9 Sep 2004 10:43:47 +0100, Francis Glassborow
> <francis@robinton.demon.co.uk> wrote:
>>> // define one (external) instance of this class for default behavior
>>> extern def_rand_type std_rand;
>
>>>What seems a little odd to me is that the linker doesn't complain that it
>>>cannot find a declaration for std_rand. I actually call this instance
from
>
> >What compiles and runs? The above is just a header file with a class
> >definition, an in class member function definition and a declaration of,
> >but not definition of std_rand. So there must be something you are not
> >showing us.
>
> Hi Francis,
>
> I suspect that he is a little "green" to abstract out the problem
> into a small compilable program. I believe that he is wondering about
> this:
Hey now, that's rather harsh in a newsgroup titled alt.comp.lang.learn.c-++.
Francis has expressed the same disbelief as I have: "The above is just a
header file with a class definition, an in class member function definition
and a declaration of, but not definition of std_rand." whereas I have said
"What seems a little odd to me is that the linker doesn't complain that it
cannot find a declaration for std_rand".
> Whether b's data members are used in the member function should not
> determine the error message. I suspect that there is a skipped step
> (eliding the passed this pointer) when a member function does not use
> data members of the class. It looks like a compiler error to me.
Thank you for the informative dissertation; I had tried adding a data member
to the class definition (to maintain state info), and your example is
exactly what happened; the linker then declared that it was unable to locate
a definition of std_rand.
The usage scenario is that this class is a default functor for a templated
class. Ideally, I would like it to maintain state information, but am unsure
how to go about doing so. The template class in which this class will be
used has a signature like so:
template <class T, typename random_type = default_rng_type,
typename allocator_type = std::allocator<T> >
class hat { /* implementation */ };
and three forms of instantiation are supported:
hat<string> names;
hat<string, my_rng_type> names( my_rng_instance );
hat<string, my_rng_type, my_alloc> names( my_rng_instance);
Is it possible to create a default_rng_type that mainains internal state
info (member data), and yet not require the user to add a line of code
instantiating a copy of default_rng_type ?
If more info is required, I can provide it; however people complain when you
post large amounts of code, people complain if you don't post the code that
they need, people complain if you attempt to describe the problem...you get
the point.
-:|:-
AngleWyrm
- Next message: Alwyn: "Re: Problems reversing strings"
- Previous message: Francis Glassborow: "Re: where is the template instance?"
- In reply to: Robert W Hand: "Re: where is the template instance?"
- Next in thread: Alwyn: "Re: where is the template instance?"
- Reply: Alwyn: "Re: where is the template instance?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|