Re: where is the template instance?

From: AngleWyrm (no_spam_anglewyrm_at_hotmail.com)
Date: 09/09/04


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



Relevant Pages

  • error C2276; passing &member function to _beginthreadex
    ... member function as "static" but I've not been able to find a compile-able ... syntax by going down that road. ... i.e. a reference to the class object itself, and that therefore when passing ... Apologies if I've missed out any code here - suffice to say it all compiles ...
    (microsoft.public.vc.language)
  • firefox error
    ... declaration of `PRAddrInfo' with no type ... nsHostResolver.h:209: error: ISO C++ forbids ... nsDNSService2.cpp: In member function `virtual ... gmake: Leaving directory ...
    (freebsd-questions)
  • Re: invalid access to non-static data member
    ... >>Is gcc right to complain? ... I thought arguments to sizeof are not evaluated. ... I'd like to be able to evaluate this macro outside of the scope (or do I ... > gives you the sizemember function for free, ...
    (comp.lang.cpp)
  • Re: Attributed programming and injected code
    ... > What is the way to overwrite COM functions, like QueryInterface for ... > declaration to the object result in error "member function already ...
    (microsoft.public.vc.atl)
  • Re: Static Function Modifer
    ... William DePalo wrote: ... That pointer would conflict with the declaration of thread ... non-static member functions cannot be used a thread procs ... Only a non-member function or a static member function can be converted ...
    (microsoft.public.vc.language)