|
-
March 15th, 2007, 09:38 AM
#1
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.
-
March 15th, 2007, 12:01 PM
#2
Re: functor parameter problem
do anyonje know its kind of urgent
-
March 15th, 2007, 12:25 PM
#3
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,
-
March 15th, 2007, 01:07 PM
#4
Re: functor parameter problem
What is the third parameter intended to be used for?
-
March 15th, 2007, 01:31 PM
#5
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()!
-
March 15th, 2007, 10:08 PM
#6
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.
-
March 15th, 2007, 11:03 PM
#7
Re: functor parameter problem
 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.
-
March 15th, 2007, 11:54 PM
#8
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);
}
-
March 16th, 2007, 12:19 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|