template members in a non-template class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nico Massi

    template members in a non-template class


    Hi NG!

    I have a class A that should store a vector of pointers to objects of class
    B.
    But class B contains a template argument and each of the stored objects in
    class A could have a different template argument. So i need a way to store
    an array of template objects in a non-template class. Obviously this wont
    work
    cause a can`t tell the compiler which template argument to use.
    So whats the usual way to solve such a situation?

    The first solution that comes to my mind is, create a non-template base
    interface to class B and store pointers to that base interface in A.
    But i think this is not the best solution for that kind of problem.
  • White Wolf

    #2
    Re: template members in a non-template class

    Nico Massi wrote:[color=blue]
    > Hi NG!
    >
    > I have a class A that should store a vector of pointers to objects of
    > class B.
    > But class B contains a template argument and each of the stored
    > objects in class A could have a different template argument. So i
    > need a way to store an array of template objects in a non-template
    > class. Obviously this wont work
    > cause a can`t tell the compiler which template argument to use.
    > So whats the usual way to solve such a situation?
    >
    > The first solution that comes to my mind is, create a non-template
    > base interface to class B and store pointers to that base interface
    > in A.
    > But i think this is not the best solution for that kind of problem.[/color]

    IMHO you are trying to do some very suspicious desing. I suggest that you
    give us a higher level view of this problem (like: I want to handle
    different complex numbers). Try stay away in that case from C++ terms (if
    it is feasible) and just try to define the problem. I guess there should be
    an easier solution.

    --
    WW aka Attila


    Comment

    • Nico Massi

      #3
      Re: template members in a non-template class

      On Fri, 29 Aug 2003 20:07:01 +0300, White Wolf <wolof@freemail .hu> wrote:
      [color=blue]
      > Nico Massi wrote:[color=green]
      >> Hi NG!
      >>
      >> I have a class A that should store a vector of pointers to objects of
      >> class B.
      >> But class B contains a template argument and each of the stored
      >> objects in class A could have a different template argument. So i
      >> need a way to store an array of template objects in a non-template
      >> class. Obviously this wont work
      >> cause a can`t tell the compiler which template argument to use.
      >> So whats the usual way to solve such a situation?
      >>
      >> The first solution that comes to my mind is, create a non-template
      >> base interface to class B and store pointers to that base interface
      >> in A.
      >> But i think this is not the best solution for that kind of problem.[/color]
      >
      > IMHO you are trying to do some very suspicious desing. I suggest that
      > you
      > give us a higher level view of this problem (like: I want to handle
      > different complex numbers). Try stay away in that case from C++ terms
      > (if
      > it is feasible) and just try to define the problem. I guess there should
      > be
      > an easier solution.
      >[/color]


      ok here is what i will do:
      i would be able to configure my app with a config file where i could set
      some values
      mostly there are simple values ( int, float, string would cover around 80% )
      but i would also be able to read complex types like a 3D Vector or an RGB
      color value
      so i thought templates would be the way to go for the config values

      for the config values i need a class that known all possible config values
      by their name
      the values would be saved in a config class where the app can query the
      config for a value
      by specifying its name

      Comment

      • llewelly

        #4
        Re: template members in a non-template class

        Nico Massi <desertswat@gmx .de> writes:
        [color=blue]
        > On Fri, 29 Aug 2003 20:07:01 +0300, White Wolf <wolof@freemail .hu> wrote:
        >[color=green]
        >> Nico Massi wrote:[color=darkred]
        >>> Hi NG!
        >>>
        >>> I have a class A that should store a vector of pointers to objects of
        >>> class B.
        >>> But class B contains a template argument and each of the stored
        >>> objects in class A could have a different template argument. So i
        >>> need a way to store an array of template objects in a non-template
        >>> class. Obviously this wont work
        >>> cause a can`t tell the compiler which template argument to use.
        >>> So whats the usual way to solve such a situation?
        >>>
        >>> The first solution that comes to my mind is, create a non-template
        >>> base interface to class B and store pointers to that base interface
        >>> in A.
        >>> But i think this is not the best solution for that kind of problem.[/color]
        >>
        >> IMHO you are trying to do some very suspicious desing. I suggest
        >> that you
        >> give us a higher level view of this problem (like: I want to handle
        >> different complex numbers). Try stay away in that case from C++
        >> terms (if
        >> it is feasible) and just try to define the problem. I guess there
        >> should be
        >> an easier solution.
        >>[/color]
        >
        >
        > ok here is what i will do:
        > i would be able to configure my app with a config file where i could
        > set some values
        > mostly there are simple values ( int, float, string would cover around 80% )
        > but i would also be able to read complex types like a 3D Vector or an
        > RGB color value
        > so i thought templates would be the way to go for the config values
        >
        > for the config values i need a class that known all possible config
        > values by their name
        > the values would be saved in a config class where the app can query
        > the config for a value
        > by specifying its name[/color]

        hm. Maybe boost::any is helpful?


        Comment

        Working...