473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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<_Traits>::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_sorted
) 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_sorted
) const
{
if (all_nodes_sorted.find(&node) != all_nodes_sorted.end()) //
***** ERROR HERE *****
return true;
else
return false;
} // repeated_state_checker_t<4>::seen_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_before(
new_node,
all_nodes_sorted
)

// 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(cost_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_sorted:
std::set<node_t *, node_sort_t> all_nodes_sorted;

// Definition of node_sort_t:
class node_sort_t
{
public:
bool operator()(const node_t *lhs, const node_t *rhs) const
{
return (lhs->state < rhs->state);
}
};
Jul 22 '05 #1
4 1487
* "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_sorted
Make that
std::set<T1 const*, T2>& all_nodes_sorted
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_sorted
) const
{
if (all_nodes_sorted.find(&node) != all_nodes_sorted.end()) //
return true;
else
return false;
Make that
return (all_nodes_sorted.find(&node) != all_nodes_sorted.end());
} // repeated_state_checker_t<4>::seen_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_sorted
Make that
std::set<T1 const*, T2>& all_nodes_sorted
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_sorted
) const
{
if (all_nodes_sorted.find(&node) != all_nodes_sorted.end()) //
return true;
else
return false;
Make that
return (all_nodes_sorted.find(&node) != all_nodes_sorted.end());
} // repeated_state_checker_t<4>::seen_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_sorted
) const
{
if (all_nodes_sorted.find(&node) !=
all_nodes_sorted.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_sorted
) const
{
if (all_nodes_sorted.find(&node) !=
all_nodes_sorted.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
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...
6
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 {
8
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,...
5
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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...

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.