CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    [RESOLVED] help with template template parameters

    Hello gurus!

    I need some help understanding template template parameters.
    Outline of what I'm trying to do is to pass a template vector which is stored in a map,
    to a template class that is expecting a vector.
    Sort of like,
    Psuedo
    Code:
     template class Foo<A, vector V, B, std::map M>;
    In Foo, create M<std::string, V<B<A > > > X;
    
    Define B like;
    template class<A, vector V> B;
    
    Pass X::iterator-second to C; // error here
    Simplifying it only using vector works,
    but when I adapt this workable solution to the model I want,
    I get a compilation error (minGW g++).
    I spent all night last night and this morning, but I'm stump.

    cut down version of class Foo is
    Code:
    template
    <
        typename Device,
        template<typename> class Container = std::vector,
        template<typename> class Configure = Config,
        template<typename, typename> class Registry = std::map
    >
    class BasicSystem
    {
    template <typename DeviceTrait>
    friend std::ostream& operator<<(std::ostream&, const BasicSystem<DeviceTrait*>&);
    
    public:
        BasicSystem();
    
        // UI
        ResultCode start();
    
    private:
        typedef Registry<Input, Container<Configure<Device*> > > iComponent;
        iComponent iDevice;
    };
    and start() member function is a simple initialization prcedure, like
    Code:
    //////////////////////////////////////////////////////////////////////////////80
    // start method
    template
    <
        typename Device,
        template<typename> class Container,
        template<typename> class Configure,
        template<typename, typename> class Registry
    >
    ResultCode BasicSystem<Device, Container, Configure, Registry>::start()
    {
        // temporary test
        typename iComponent::iterator iter = iDevice.begin();
        iter->second.at(0).load("loadme.conf");
    
        ///// error here  /////
        iter->second.at(0).initDevice(iter->second.at(0));
    
        return 0;
    }
    and the template class that I'm trying to pass to is
    Code:
    template <typename DeviceTrait, template<typename> class Container = std::vector>
    class Config
    {
    public:
        Config();
    
        // UI
        Bool load(CRString);
        ResultCode initDevice(Container<DeviceTrait*>&, Bool doShow = true);
    };
    and initDevice method is defined like
    Code:
    template <typename DeviceTrait, template<typename> class Container>
    ResultCode
    Config<DeviceTrait, Container>::initDevice(Container<DeviceTrait*>& ref, Bool doShow)
    {
        std::for_each(ref.begin(), ref.end(),
            std::bind2nd(std::mem_fun(&DeviceTrait::init), doShow));
        return 19;
    }
    The compiler keeps telling me that there's no matching functioncall to initDevice(),
    but it is myunderstanding that I'm correctly (but apparently wrong) passing a vector.

    I'd appreciate if anyone can help.
    Thanks

    Edit: All these classes are defined in a namespace, if that matters... I'm not sure.
    Last edited by potatoCode; October 14th, 2009 at 01:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured