problem calling function

This is a discussion on problem calling function within the C++ Programming forums, part of the General Programming Boards category; I have a function: Code: list<Coord>::iterator partition(list<Coord>& mList, list<Coord>::iterator it){ double x = it->get_x(); double y = it->get_y(); double dist ...

  1. #1
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391

    problem calling function

    I have a function:
    Code:
    list<Coord>::iterator partition(list<Coord>& mList, list<Coord>::iterator it){
    
        double x = it->get_x();
        double y = it->get_y();
    
        double dist = distance(x,y)/3;
    
        return it;
    }
    I'm getting this error when it reaches the call to the distance function:
    Code:
    /usr/include/c++/4.1.3/bits/stl_iterator_base_types.h: In instantiation of 'std::iterator_traits<double>’:
    main3.cpp:205:   instantiated from here
    /usr/include/c++/4.1.3/bits/stl_iterator_base_types.h:129: error: ‘double’ is not a class, struct, or union type
    but if I just replace the function call with the distance formula itself, it works.

    any ideas??
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    distance is a function from <iterator> that returns the distance between two iterators, and I think that might be causing problems. Sorry. Maybe call your distance function something else? We can at least see if that's what's causing problems.

  3. #3
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by tabstop View Post
    distance is a function from <iterator> that returns the distance between two iterators, and I think that might be causing problems. Sorry. Maybe call your distance function something else? We can at least see if that's what's causing problems.
    Yeah, that was it. Amazing how I've never ran into that problem before using the name distance to denote a distance function. Does this problem arise only if you're using <iterator> or <list> or something of the sort?
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The culprit is really the line
    Code:
    using namespace std;
    since normally you would have to use std::distance for the version in <iterator>. But yeah, if you don't include that header, you also won't import the function name. (Of course, then you can't use iterators, so that's not really a solution here.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Not including the header is too risky, because another header may well include it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  4. problem with function calling
    By Andystudent in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2004, 07:12 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21