No Matching Function Call for Constructor

This is a discussion on No Matching Function Call for Constructor within the C++ Programming forums, part of the General Programming Boards category; 'am using maps for the first time. Can not figure out why the Code: o_f _sin(&d_sin); is not working. Code: ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Cupertino
    Posts
    2,589

    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 01:28 PM.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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

  3. #3
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Cupertino
    Posts
    2,589
    Why? I've not used a single object without the constructor I wrote. Does the map require me to do so?
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,664
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,664
    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, 11:46 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01: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


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