no matching function for call to

This is a discussion on no matching function for call to within the C++ Programming forums, part of the General Programming Boards category; here's the code, when calling functionC, the error messge is "no matching function for call to `sampleB::functionB (sampleA&)" Code: class ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    25

    no matching function for call to

    here's the code, when calling functionC, the error messge is
    "no matching function for call to `sampleB::functionB (sampleA&)"

    Code:
    class sampleA
    {
      public:
      
      sampleA(){}
      
      void functionA(){}
      
      private:
    
    };
    
    class sampleB
    {
       public:
       
      sampleA object1;
      
      sampleB(){}
      
       int functionB (sampleA& in)
      {
        in.functionA();
      }
       
       private:
    };
    
    void functionC (sampleB in2)
    {
      in2.functionB(in2.object1);
    }

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    the code above looks fine, but when applying it into program, the error happens:
    " no matching function for call to `ocean::getcoordinates (submarine &)' "


    Code:
    typedef struct target
    {
            int x;
            char y;
            bool hit;
            target *next;
    } Target;
    
    target *newTarget()
    {
           target *temp;
           temp = new(target);
           temp->hit = false;
           temp->next = NULL;
           return temp;
    }
    
    class submarine
    {
          public:
                 submarine()
                 {
                            head = newTarget();
                            head->next = NULL;
                 }
    
                 void setsub(string subname, int subsize, int depth)
                 {
                            name = subname;
                            size = subsize;
                            maxdepth = depth;
                 }
    
                 int getcoordinates()
                 {
                            int temp;
                            char tempchar;
                            cout<<"Please enter the X coordinate. (1-10)\n";
                            cin>>temp;
                            while (!(temp >= 1 && temp <= 10))
                            {
                                  cout<<"Inappropriate coordinate. Try again.\n";
                                  cin>>temp;
                            }
                            head->x = temp;
                }
    
    
          private:
                  target *head;
                  int size, maxdepth;
                  string name;
                  bool destroyed;
    
    };
    
    
    class ocean
    {
          public:
                 ocean()
                 {
                        sub.setsub("Stealth Spy Sub", 1, 100);
                 }
    
                 int getsubcoordinates (submarine& sub)
                 {
                      sub.getcoordinates();
                 }
    
    
                 submarine sub;
          private:
                  int score, ammo;
    
    
    };
    
    
    void setup(ocean& in, ocean& in2)
    {
    
              in.getcoordinates(in.sub);
    }

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    ocean doesn't have a memberfunction called getcoordinates.
    it is called getsubcoordinates.
    Kurt

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,739
    This one is easy. You don't have a getcoordinates(sub&) method for ocean objects, but you do have a getsubcoordinates(sub&) method.

    EDIT: Kurt types faster than me.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    25
    Quote Originally Posted by ZuK
    ocean doesn't have a memberfunction called getcoordinates.
    it is called getsubcoordinates.
    Kurt
    ,thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Interesting behavior with explicit copy constructor
    By Clairvoyant1332 in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2008, 03:19 PM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  5. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM

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