[LC++]Ambiguous error

Carlo Wood carlo at alinoe.com
Tue Nov 25 23:35:02 UTC 2003


You don't deserve an answer.  Can't you take
the time to at least provide us with an example
that you TESTED yourself?

On Tue, Nov 25, 2003 at 12:48:36PM +0100, Peter Poulsen wrote:
> 
> I have the following:
> 
> class Node { // some stuff };

This doesn't compile, the last "};" is part of the comment.

> class Node_Contatainer {

That contains a typo.

> public:
>         Node * get_node(unsigned int i) const { return _nodes[i]; }
>         Node * get_node(string name) {

This won't compile without an #include <string>
and a 'using namespace std;', you should use std::string.

>                 for(unsigned int i = 0; i < _node.size(); i++) {

What the f* is _node ?
Another typo no doubt.

>                         if(_nodes[i]->get_name() == name)

`get_name' was never declared.

>                                 return _nodes[i];
>                 }
>                 return NULL;
>         }
> private:
>         vector<Node*> _nodes;

This needs #include <vector> and you should write std::vector.

[...]

You coding style is also very bad...
Not to mention the bad placing of '*' and spaces
(see http://www.xs4all.nl/~carlo17/c++/const.qualifier.html)
why don't use pass a std::string const&  instead of copying
the string?

> 
> If I try to compile this with g++-3.2.3 I something like:
> 
> program.cc:15: ISO C++ says that `Node*
>   Node_Container::get_node(unsigned int) const' and `Node*
>   Node_Container::get_node(std::basic_string<char, std::char_traits<char>,
>   std::allocator<char> >)' are ambiguous even though the worst
>   conversion for the former is better than the worst conversion for the
>   latter
> 
> I don't have this problem with g++-2.95.3. Does anybody know what this
> means, and more importantly, what I do about it?

Anyway... this compiles for me:

#include <iostream>
#include <vector>

class Node { };
class Node_Container {
  std::vector<Node*> _nodes;
public:
  Node* get_node(unsigned int i) const { return _nodes[i]; }
  Node* get_node(std::string const& name) const { return NULL; }
};

int main()
{
  Node_Container* nc = new Node_Container;
  nc->get_node(0);
  return 0;
}

-- 
Carlo Wood <carlo at alinoe.com>



More information about the tuxCPProgramming mailing list