CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2010
    Posts
    3

    Virtual and inheritance, can't find the problem

    Hi, I get an "undefined reference to `vtable for controlSystem'" when compiling the following code. I can't find the problem, I thought that this compiler message appeared when you forgot to implement a virtual member, but i think it's not my case.

    Thanks in advance.

    Code:
    class controlSystem {
    	protected:
    		byte varNumber;
    		byte varSize;
    	
    	public:
    		controlSystem();
    		byte iBL (unsigned int value);
    		byte iBH (unsigned int value);
    		unsigned int b2I(byte bH, byte bL);
    		virtual unsigned int calculateOutput (unsigned int fullStatus[17]);
    		virtual void sensorUpdate (unsigned int lastValue[16], unsigned int newValue[16]);
    		virtual void saveEEPROM(unsigned int position);
    		virtual void initializeEEPROM(unsigned int position);
    		virtual void loadEEPROM(unsigned int position);
    		};
    /*fin de control System e inicio de thresholdSystem*/
    
    class thresholdSystem : public controlSystem {
    private:
      unsigned int _threshold[16];
      unsigned int _valueObj[16];
      boolean _isrising[16];
      unsigned int _active;
    
    protected:
    
    public:
      thresholdSystem();
       void saveEEPROM (unsigned int position);
       void initializeEEPROM (unsigned int position);
       void loadEEPROM (unsigned int position);
       unsigned int calculateOutput (unsigned int [17]);
       void sensorUpdate (unsigned int [16], unsigned int [16]);
    };
    
    ---------------------------
    byte controlSystem::iBL (unsigned int value) {
    ...
    }
    
    byte controlSystem::iBH (unsigned int value) {
    ...
    }
    
    unsigned int controlSystem::b2I(byte bH, byte bL) {
    ...
    }
    
    controlSystem::controlSystem () {
      int a=0;
    }
    
    
    thresholdSystem::thresholdSystem () {
      ...
    }
    
    //Cambiar código para coger dirección por parámetro
    
    void thresholdSystem::loadEEPROM (unsigned int position) {
      ...
    }
    
    void thresholdSystem::saveEEPROM (unsigned int position) {
      ...
    }
    
    void thresholdSystem::initializeEEPROM (unsigned int position) {
      ...
    }
    
    unsigned int thresholdSystem::calculateOutput (unsigned int fullStatus[17]) {
      ...
    }
    
    void thresholdSystem::sensorUpdate (unsigned int lastValue[16], unsigned int newValue[16]){
      ...
    }

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Virtual and inheritance, can't find the problem

    Where are the implementations for controlSystem?

    If you don't want to provide implementations for controlSystem, make the virtual functions pure virtuals.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  3. #3
    Join Date
    Oct 2010
    Posts
    3

    Re: Virtual and inheritance, can't find the problem

    It's in the code, isn't it?

    Code:
    controlSystem::controlSystem () {
      int a=0;
    }

  4. #4
    Join Date
    Oct 2010
    Posts
    3

    Re: Virtual and inheritance, can't find the problem

    Anyways, to make it pure virtual (the constructor) should I put
    Code:
    controlSystem::controlSystem() = 0 {}
    or should I make the entire class virtual?

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Virtual and inheritance, can't find the problem

    Quote Originally Posted by scarnia View Post
    It's in the code, isn't it?

    Code:
    controlSystem::controlSystem () {
      int a=0;
    }
    Quote Originally Posted by scarnia View Post
    Anyways, to make it pure virtual (the constructor) should I put
    Code:
    controlSystem::controlSystem() = 0 {}
    or should I make the entire class virtual?
    That's a constructor. Constructors can't be virtual (nor classes...)

    No, I'm talking about:
    virtual unsigned int calculateOutput (unsigned int fullStatus[17]);
    virtual void sensorUpdate (unsigned int lastValue[16], unsigned int newValue[16]);
    virtual void saveEEPROM(unsigned int position);
    virtual void initializeEEPROM(unsigned int position);
    virtual void loadEEPROM(unsigned int position);

    I don't see their definition (implementation) for controlSystem.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Virtual and inheritance, can't find the problem


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured