Hi,
if I compile the following code I get the error:
RemoveIf.cpp(19 ) : error C2914: 'remove_if' : cannot deduce template
argument as function argument is ambiguous
#include <algorithm>
#include <vector>
template<typena me T>
class vector_t
: public std::vector<T>
{
bool TestRemove(long Pos) const //(1)
{
return false;
}
static bool TestRemove(cons t T &) //(2)
{
return false;
}
public:
void RemoveIf()
{
erase(std::remo ve_if(begin(), end(), &vector_t<T>::T estRemove),
end()); //this is line 19
}
};
typedef struct point
{
long x;
long y;
long f;
} point;
int main()
{
vector_t<point> vp;
vp.RemoveIf();
return 0;
}
How may I force the remove_if to use the TestRemove (2) function as
predicate?
TIA.
Marco. 2 2461
On 7 Apr 2004 02:52:48 -0700, ma***********@v irgilio.it
(marco_segurini ) wrote: Hi,
if I compile the following code I get the error:
RemoveIf.cpp(1 9) : error C2914: 'remove_if' : cannot deduce template argument as function argument is ambiguous
#include <algorithm> #include <vector>
template<typen ame T> class vector_t : public std::vector<T> { bool TestRemove(long Pos) const //(1) { return false; } static bool TestRemove(cons t T &) //(2) { return false; } public: void RemoveIf() {
bool (*remover)(cons t T&) = &vector_t<T>::T estRemove;
erase(std::remo ve_if(begin(), end(), remover),
end()); //this is line 19
How may I force the remove_if to use the TestRemove (2) function as predicate?
Either the above, or add a static cast to select the function type:
erase(
std::remove_if(
begin(),
end(),
static_cast<boo l (*)(const T&)>(&vector_t< T>::TestRemove )
),
end()
);
When taking the address of an overloaded function, you need a target
type for the compiler to be able to work out which overload you are
referring to. You can specify the target type using an assignment or a
static_cast.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
On 7 Apr 2004 02:52:48 -0700, ma***********@v irgilio.it
(marco_segurini ) wrote: Hi,
if I compile the following code I get the error:
RemoveIf.cpp(1 9) : error C2914: 'remove_if' : cannot deduce template argument as function argument is ambiguous
#include <algorithm> #include <vector>
template<typen ame T> class vector_t : public std::vector<T> { bool TestRemove(long Pos) const //(1) { return false; } static bool TestRemove(cons t T &) //(2) { return false; } public: void RemoveIf() {
bool (*remover)(cons t T&) = &vector_t<T>::T estRemove;
erase(std::remo ve_if(begin(), end(), remover),
end()); //this is line 19
How may I force the remove_if to use the TestRemove (2) function as predicate?
Either the above, or add a static cast to select the function type:
erase(
std::remove_if(
begin(),
end(),
static_cast<boo l (*)(const T&)>(&vector_t< T>::TestRemove )
),
end()
);
When taking the address of an overloaded function, you need a target
type for the compiler to be able to work out which overload you are
referring to. You can specify the target type using an assignment or a
static_cast.
Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: CupOfWater |
last post by:
Hi, I'm getting some errors using remove_if that I can not fix at all.
Let me paste my code and also the error here. I went on IRC and
people were mostly no help. The compiler is g++ 3.2.3. Thanks in
advance.
/usr/include/c++/3.2.3/bits/stl_algo.h: In function `_OutputIter
std::remove_copy_if(_InputIter, _InputIter, _OutputIter,
_Predicate) ':
/usr/include/c++/3.2.3/bits/stl_algo.h:1085: instantiated from
`_ForwardIter...
|
by: Wang Tong |
last post by:
I have the following code, which removes a pair (string, int) from the
set. I defined a predicate that returns true if the string value matches.
But I am getting compiler error on the remove_if function:
Here is the code:
typedef pair<string, int> my_pair;
typedef set<my_pair> my_set;
typedef my_set::iterator my_set_p;
|
by: Paavo K |
last post by:
Hi, can anyone tell what is wrong with following code :
//..Code
class removeTest
{
public:
bool operator()(map<int, string>::value_type &d) const
{
// Just returning false to simplify code..
|
by: marco_segurini |
last post by:
Hi,
if I compile the following code I get the error:
RemoveIf.cpp(19) : error C2914: 'remove_if' : cannot deduce template
argument as function argument is ambiguous
#include <algorithm>
#include <vector>
|
by: bahadir.balban |
last post by:
Hi,
What's the best way to implement an overloaded function in C? For
instance if you want to have generic print function for various
structures, my implementation would be with a case statement:
void print_structs(void * struct_argument, enum struct_type stype)
{
switch(stype) {
case STRUCT_TYPE_1:
| |
by: cybertof |
last post by:
Hello,
Is it possible in C# to have 2 overloaded functions with
- same names
- same parameters
- different return type values
If no, is it possible in another language ?
|
by: Adam Hartshorne |
last post by:
Hi All,
I want to do the following,
I have a std::vector<Patch> called say vs. Now there is a bool variable
in the class called outlier, which may be access by getOutlierStatus()
method.
Now I want to remove all "Patch"es in the vector dataPatches, whose
outlier variable is set to true.
|
by: Jon Rea |
last post by:
Hello all,
Sorry if this is long, but I wanted to be specific...
Can anyone shed any light on the following errors in the context of the
following example code:
cullMethod1(); // compiles, but not what we want - we cant access
m_Exclustions
|
by: Angus |
last post by:
Hi
I have a class CRequest with a function:
bool IsFinished() const;
I have a list of these CRequests - list<CRequestmylist.
I create a function object to find if a CRequest is finished:
class is_finished : public std::unary_function<CRequest, bool>
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |