473,569 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parameter / argument mismatch in template scenario


Hello all,

I hope the context to my problem shown below is adequate but not
overwhelming. I tried to keep it minimal.

At the line indicated (in comment form) in the source below, the following
error is occurring (VC++ 7.1):
error C2663: 'std::_Tree<_Tr aits>::find' : 2 overloads have no legal
conversion for 'this' pointer

In Comeau speak:
error: argument of type ... is incompatible with parameter of type ...

If I change part of the line in question to:
((T1 *) &node)

everything works fine (both platforms). However, I may not use the
C++-style casts here - failure still occurs in that case.

Does anybody have nay idea what might be going on?

Thanks,
Dave
// Class declaration:
template <int n>
class repeated_state_ checker_t
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
) const;
};

// Definition of class full specialization:
template <>
class repeated_state_ checker_t<4>
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
) const
{
if (all_nodes_sort ed.find(&node) != all_nodes_sorte d.end()) //
***** ERROR HERE *****
return true;
else
return false;
} // repeated_state_ checker_t<4>::s een_before
};

// The class above is a template parameter to my main class; my main class
inherits from the
// template parameter and attempts to invoke the seen_before() method of the
base
// subobject as follows:
REPEATED_STATE_ CHECKER::seen_b efore(
new_node,
all_nodes_sorte d
)

// Definition of the type of new_node is shown below. This struct is
embedded in a class template and references
// some of that class template's template parameters.
struct node_t
{
node_t(
const STATE_T &state_p,
int depth_p,
int cost_to_reach_p ,
const node_t *parent_p = NULL,
const OP_T &op_p = OP_T()
):
state(state_p),
depth(depth_p),
cost_to_reach(c ost_to_reach_p) ,
parent(parent_p ),
op(op_p)
{
}

STATE_T state;
int depth;
int cost_to_reach;
const node_t *parent; // Equals NULL for root node
OP_T op; // Meaningful only if parent !=
NULL
};

// Definition of all_nodes_sorte d:
std::set<node_t *, node_sort_t> all_nodes_sorte d;

// Definition of node_sort_t:
class node_sort_t
{
public:
bool operator()(cons t node_t *lhs, const node_t *rhs) const
{
return (lhs->state < rhs->state);
}
};
Jul 22 '05 #1
4 1740
* "Dave" <be***********@ yahoo.com> schriebt:

I hope the context to my problem shown below is adequate but not
overwhelming. I tried to keep it minimal.
There's much that's irrelevant, yes. ;-)

In Comeau speak:
error: argument of type ... is incompatible with parameter of type ...

If I change part of the line in question to:
((T1 *) &node)

everything works fine (both platforms). However, I may not use the
C++-style casts here - failure still occurs in that case.
You may technically use the C++ casts, specifically const_cast.
Does anybody have nay idea what might be going on?
Yes, almost everybody have nay idea what might be going on.

// Class declaration:
template <int n>
class repeated_state_ checker_t
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
Make that
std::set<T1 const*, T2>& all_nodes_sorte d
or even better use a typedef'ed name.

) const;
};

// Definition of class full specialization:
template <>
class repeated_state_ checker_t<4>
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
) const
{
if (all_nodes_sort ed.find(&node) != all_nodes_sorte d.end()) //
return true;
else
return false;
Make that
return (all_nodes_sort ed.find(&node) != all_nodes_sorte d.end());
} // repeated_state_ checker_t<4>::s een_before
};


--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
* "Dave" <be***********@ yahoo.com> schriebt:

I hope the context to my problem shown below is adequate but not
overwhelming. I tried to keep it minimal.
There's much that's irrelevant, yes. ;-)

In Comeau speak:
error: argument of type ... is incompatible with parameter of type ...

If I change part of the line in question to:
((T1 *) &node)

everything works fine (both platforms). However, I may not use the
C++-style casts here - failure still occurs in that case.
You may technically use the C++ casts, specifically const_cast.
Does anybody have nay idea what might be going on?
Yes, almost everybody have nay idea what might be going on.

// Class declaration:
template <int n>
class repeated_state_ checker_t
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
Make that
std::set<T1 const*, T2>& all_nodes_sorte d
or even better use a typedef'ed name.

) const;
};

// Definition of class full specialization:
template <>
class repeated_state_ checker_t<4>
{
public:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2> &all_nodes_sort ed
) const
{
if (all_nodes_sort ed.find(&node) != all_nodes_sorte d.end()) //
return true;
else
return false;
Make that
return (all_nodes_sort ed.find(&node) != all_nodes_sorte d.end());
} // repeated_state_ checker_t<4>::s een_before
};


--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #3
Dave wrote:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2>
&all_nodes_sort ed
) const
{
if (all_nodes_sort ed.find(&node) !=
all_nodes_sorte d.end()) // ***** ERROR HERE *****
return true;
else
return false;
}


The problem is that &node is const T1*
while find expects a non-const pointer.
Martin

--
Quidquid latine dictum sit, altum viditur.
Jul 22 '05 #4
Dave wrote:
template <typename T1, typename T2>
bool seen_before(
const T1 &node,
const std::set<T1 *, T2>
&all_nodes_sort ed
) const
{
if (all_nodes_sort ed.find(&node) !=
all_nodes_sorte d.end()) // ***** ERROR HERE *****
return true;
else
return false;
}


The problem is that &node is const T1*
while find expects a non-const pointer.
Martin

--
Quidquid latine dictum sit, altum viditur.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1499
by: Dave | last post by:
Hello all, I hope the context to my problem shown below is adequate but not overwhelming. I tried to keep it minimal. At the line indicated (in comment form) in the source below, the following error is occurring (VC++ 7.1): error C2663: 'std::_Tree<_Traits>::find' : 2 overloads have no legal conversion for 'this' pointer
10
1774
by: rg | last post by:
Hi all, I was wondering if anyone had dealt with a similar problem. I need to use a template function as the parameter for a particular function (also template function). The program compiles into an object file but then at the final stage it says that it can't find template function. The platform is WindowsXP Pro, MSCV++ ..Net. More...
6
9249
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
3
2735
by: Capstar | last post by:
Hi NG, I am trying to get the attached piece of code to work, but I can't figure out what I'm doing wrong. To me it seems that when I don't pass an argument to x::do_something, it should use the default value, which is always_true(). but gcc says: no matching function for call to `x::do_something()' and msvs says: could not deduce...
8
3139
by: Tony Johansson | last post by:
Hello Experts! What does this mean actually. If you have a template with a type and non-type template argument, say, like this template<typename T, int a> class Array {. . .}; then A<int, 1> and A<int, 2> are different types. Now, if the A template
2
2753
by: Siegfried Weiss | last post by:
Hi guys, i give up finding a solution by reading or by trial & error. Hope, YOU can help me! (Sorry for my rather long posting.) Stroustrup says, that templates could be declared with - type parameter, e.g. template<class T> - parameters with *simple* types like int, e.g. template<int size> - template parameter, e.g. template<...
3
3563
by: Fei Liu | last post by:
Hello, We all know that a template function can automatically deduce its parameter type and instantiate, e.g. template <tpyename T> void func(T a); func(0.f); This will cause func<floatto be instantiated. The user does not have
5
6628
by: puzzlecracker | last post by:
C++ standard says the following: I am reading through c++ standard and have a difficulty understanding the difference between these two terms. Thanks, puzzlecracker
8
2947
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
jinu1996
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...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2113
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
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.