Thread: template specialization

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    template specialization

    I wanted to specify two very, very similar classes without having to write them out twice. However, when I specify member functions of one of the two possible cases, the compiler complains that the type I'm referring to is incomplete. What am I missing in this method? (stripped down)
    Code:
    template<class unary_func, bool Kd_weighted = false>
    class sum : public func2d
    {
    public:
        void operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd = 1.0);
    private:
        grid::data_type s;
        unary_func f;
    };
    
    template<class unary_func>
    void sum<unary_func,false>::operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd)
    {
            s += f( g(x,y) );
    }
    
    template<class unary_func>
    void sum<unary_func,true>::operator()(grid::size_type x, grid::size_type y, grid::base_type & g, grid::data_type Kd)
    {
            s += Kd * f( g(x,y) );
    }
    Code:
    error: invalid use of incomplete type ‘class functions::sum<unary_func, false>’|
    error: declaration of ‘class functions::sum<unary_func, false>’|
    error: invalid use of incomplete type ‘class functions::sum<unary_func, true>’|
    error: declaration of ‘class functions::sum<unary_func, true>’|
    Thanks.

    *edit* Of course the classes are incomplete, but won't they be written at compile time, since I'm using them? Does the 'bool' not limit us to only two possibilities for a given unary_func?
    Last edited by CodeMonkey; 12-28-2008 at 11:41 PM.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Template specialization
    By CornedBee in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 02:02 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM