Thread: No Matching Function Call for Constructor

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    No Matching Function Call for Constructor

    'am using maps for the first time. Can not figure out why the
    Code:
    o_f  _sin(&d_sin);
    is not working.
    Code:
    #include<map>
    #include<cmath>
    class o_f        //Operator Functions 
    {
        public:
        double (*func)(double);
        o_f(double (*fun)(double))      {func = fun;};
    };
    double d_sin(double x)               //double_sin
    {
        return sin(x);
    }
    int main()
    {
        std::map<int,o_f> m;
        o_f  _sin(&d_sin);
        m[1]=_sin;
    
        return 0;
    }
    Last edited by manasij7479; 02-07-2011 at 02:28 PM.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    As written you need to provide a default constructor for o_f.

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Why? I've not used a single object without the constructor I wrote. Does the map require me to do so?

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Yes, because you're storing objects rather than pointers to objects, it needs to know the size when you create the map.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The lack of default contructor has nothing to do with knowing the size of the class.

    The problem is with how operator[] works for map. If the item is not present in the map, it is first inserted using the default constructor and then a reference to the new item is returned. It's only to that reference that you are assigning _sin to.

    If you don't want to add a default constructor to the class, you can still use map, but not operator[].

    To insert items you can use:
    Code:
    m.insert(std::make_pair(1, _sin));
    and to look it up, you'd need the find member function.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    I see...well I made an invalid assumption I shouldn't have. To quote your signature:
    I might be wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2009, 12:46 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

Tags for this Thread