CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    functor parameter problem

    hi i have a problem.

    error: no matching function for call to `test1(int&, int)'

    Code:
    namespace test0 {
    
    	template<typename test10, typename test11>
    	const bool test1(bool&, const test10&, const test11&)
    	{
    		return(true);
    	}
    }
    
    		template<typename test10, typename test11, typename test12>
    		const bool test1(test10&, const test11&, const test12& = test0::test1)
    		{
                return(false);
    		}
    
    int main(void)
    {
        int x = 0;
        test1(x, 0);
    }
    i dont know why functor wrong.
    Last edited by Mitsukai; March 15th, 2007 at 10:10 AM.

  2. #2
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: functor parameter problem

    do anyonje know its kind of urgent

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: functor parameter problem

    Your test1 template takes three concrete (non-default) arguments. You are instantiating the template using only two arguments.
    Code:
    template<typename test10, typename test11, typename test12>
    bool test1(test10&, const test11&, const test12& = test0::test1)
    {
    }
    
    int main(void)
    {
        int x = 0;
        test1(x, 0, true);  // this works
    }
    This compiles fine with Comeau.

    Regards,

  4. #4
    Join Date
    Dec 2003
    Location
    Middletown, DE
    Posts
    67

    Re: functor parameter problem

    What is the third parameter intended to be used for?

  5. #5
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: functor parameter problem

    Yep, template argument deduction on the second test1 overload can't be complete as test12 can't be deduced.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  6. #6
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: functor parameter problem

    i would rather hear a solution.

    i have tried this:


    Code:
        struct
        {
            template<typename test10, typename test11>
            const bool operator()(bool& x, const test10& y , const test11& z) const
            {
                return(x = true);
            }
        } test1;
    
    		template<typename test10, typename test11, typename test12>
    		const bool test2(test10& x, const test11& y, const test12& z = test1)
    		{
    		    bool a;
    		    z(a, x, y);
                return(a);
    		}
    
    int main(void)
    {
        int x = 0;
        test2(x, 0, test1);
    }
    it should be able to deduce test12 now but still no match.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: functor parameter problem

    Quote Originally Posted by Mitsukai
    i would rather hear a solution.
    So what do you call what I posted using your original code? There were no compilation errors in the example I posted if you specify the last parameter when the template is instantiated.

    Now you've changed the code to a totally different example that doesn't compile for an entirely different set of reasons:
    Thank you for testing your code with Comeau C/C++!
    Tell others about http://www.comeaucomputing.com/tryitout !

    Your Comeau C/C++ test results are as follows:

    Comeau C/C++ 4.3.8 (Aug 19 2006 13:36:48) for ONLINE_EVALUATION_Alpha1
    Copyright 1988-2006 Comeau Computing. All rights reserved.
    MODE:strict errors C++

    "ComeauTest.c", line 4: warning: type qualifier on return type is meaningless
    const bool operator()(bool& x, const test10& y , const test11& z) const
    ^

    "ComeauTest.c", line 8: error: use of a type with no linkage to declare a variable
    with linkage
    } test1;
    ^

    "ComeauTest.c", line 11: warning: type qualifier on return type is meaningless
    const bool test2(test10& x, const test11& y, const test12& z = test1)
    ^

    "ComeauTest.c", line 21: error: a template argument may not reference an unnamed
    type
    test2(x, 0, test1);
    ^

    2 errors detected in the compilation of "ComeauTest.c".

    In strict mode, with -tused, Compile failed
    Code:
    struct test1
    {
         template<typename test10, typename test11>
         bool operator()(bool& x, const test10& y , const test11& z) const
         {
              return(x = true);
         }
    };
    
    test1 test_inst;
    
    template<typename test10, typename test11, typename test12>
    bool test2(test10& x, const test11& y, const test12& z = test_inst)
    {
       bool a;
       z(a, x, y);
       return(a);
    }
    
    int main(void)
    {
        int x = 0;
        test2(x, 0, test_inst);
    }
    This compiles fine.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; March 15th, 2007 at 11:12 PM.

  8. #8
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: functor parameter problem

    but this does not .

    Code:
        struct test1t
        {
            template<typename test10, typename test11>
            const bool operator()(bool& x, const test10& y , const test11& z) const
            {
                return(x = true);
            }
        };
    
        test1t test1;
    
    		template<typename test10, typename test11, typename test12>
    		const bool test2(test10& x, const test11& y, const test12& z = test1)
    		{
    		    bool a;
    		    z(a, x, y);
                return(a);
    		}
    
    int main(void)
    {
        int x = 0;
        test2(x, 0);
    }

  9. #9
    Join Date
    Apr 1999
    Posts
    27,449

    Re: functor parameter problem

    It doesn't compile for the same reasons as the first example.

    Regards,

    Paul McKenzie

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