Member function not found?

This is a discussion on Member function not found? within the C++ Programming forums, part of the General Programming Boards category; Apparently the function bool send(unsigned char*, int) is not declared...but I am looking at it in the .h file. Or ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    117

    Member function not found?

    Apparently the function bool send(unsigned char*, int) is not declared...but I am looking at it in the .h file. Or at least I think so...can someone point out to me what I am missing here?
    Code:
    #ifndef ROBOT_H
    #define ROBOT_H
    #include "rs232.h"
    
    class Robot
    {
    public:
        Robot(int, int);
        virtual ~Robot();
    
        int& getPort();
        void setPort(int&);
    
        int& getBaudRate();
        void setBaudRate(int&);
    
        SerialConnect& getConnection();
    
        bool send(unsigned char*, int);
    
    private:
        int port;
        int baudrate;
        SerialConnect connection;
    };
    
    #endif // ROBOT_H
    Code:
    #include "Robot.h"
    
    Robot::Robot(int portNo, int br) : port(portNo), baudrate(br) {
        if(connection.OpenComport(port, baudrate))
            printf("no worked\n");
        else
            printf("worked\n");
    }   //END ROBOT()
    
    Robot::~Robot() {
        connection.CloseComport(port);
    }   //END ~ROBOT()
    
    
    SerialConnect& Robot::getConnection() {return connection;}
    
    
    int& Robot::getPort() {return port;}
    void Robot::setPort(int& p) {port = p;}
    
    int& Robot::getBaudRate() {return baudrate;}
    void Robot::setBaudRate(int& br) {baudrate = br;}
    
    bool Robot::send(unsigned char* bytes, int size) {
        if(connection.SendBuf(port, bytes, size) == -1)
            return false;
        else
            return true;
    
    }   //END SEND
    The error is -
    Robot.cpp:24: error: no ‘bool Robot::send(unsigned char*, int)’ member function declared in class ‘Robot’

    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The code you posted does not generate that error. Please post code that demonstrates the problem.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    117
    Whenever I do
    Code:
    g++ -o go Robot.h Robot.cpp rs232.h rs232.c main.cpp
    into the terminal I get that error. Since I posted this I added another function which also gives me the same error. It seems like it shouldn't give me that error which is why I am confused.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why are you putting .h files on your command line? (Hint: Don't.) But g++ here is entirely happy with the code as you have it here.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    117
    Thanks for the tip. I wish I could say I wasn't getting errors...but for some reason I am getting -
    Robot.cpp:23: error: no ‘void Robot::close()’ member function declared in class ‘Robot’
    Robot.cpp:25: error: no ‘bool Robot::send(unsigned char*, int)’ member function declared in class ‘Robot’

    I don't know why because the functions are right there. Although when I right click on the functions in Code::Blocks and go to Find Declaration it tells me "Not Found." I won't keep bumping this thread, but I really am getting the errors. I'll keep trying to figure out why and if I do I will post it in here.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, close() would appear to be a legitimate error, since you don't have close() in the class as posted above (maybe you do in yours I don't know). I'd go over your .h file with a fine-tooth comb (maybe a stray close-curly brace is closing your class too soon?)

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    117
    could it have something at all to do with compiling the C file, rt232.c?

  8. #8
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    maybe your #include should be
    #include "rs232.h"

    not
    #include "Robot.h"
    You ended that sentence with a preposition...Bastard!

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    117
    Okay I found the problem. There was a precompiled Robot header in the same directory. Once I deleted that it compiled fine. Thanks for the replies.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  2. Finding a word in a string.
    By esbo in forum C Programming
    Replies: 15
    Last Post: 08-28-2006, 07:48 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. function pointers and member functions
    By thor in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2002, 03:22 PM

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