Thread: Problem with compiling and constructor

  1. #1
    Registered User
    Join Date
    Dec 2015
    Posts
    92

    Problem with compiling and constructor

    I am fighting with the GCC compiler, problem occurs in the constructor of the LCD class, when I try to instantiate new LCDTransmitter:
    Code:
     this->i2cTransmitter = new I2CTransmitter(i2cAdapter);
    I get the following errors:

    Error no matching function for call to 'I2CTransmitter::I2CTransmitter(I2CAdapter*&)'

    Message no known conversion for argument 1 from 'I2CAdapter*' to 'const I2CTransmitter&' LCD_I2C_4bit

    Message candidate expects 0 arguments, 1 provided LCD_I2C_4bit

    Message I2CTransmitter::I2CTransmitter(const I2CTransmitter&)

    Message I2CTransmitter::I2CTransmitter()

    I don't know why compiler thinks that I am calling Copy constructor of class I2CTransmitter since I override default constuctor with a parameter object pointer of class I2CAdapter:

    Code:
    LCDTransmitter(I2CAdapter* i2cAdapter);

    LCD.h
    Code:
    #include "I2CAdapter.h"
    #include "I2CTransmitter.h"
    #include <util/delay.h>
    
    class LCD
    {
        private:
            I2CTransmitter* i2cTransmitter;
            uint8_t numLines;
            uint8_t numColumns;
            
        public:
            LCD(I2CAdapter* i2cAdapter);
            void open(uint8_t numLines, uint8_t numColumns);
            int8_t writeString(const char* text);
            int8_t writeCommand(uint8_t command);
            int8_t setCursor(uint8_t x, uint8_t y);
            
        private:
            void checkIfBusy();
    };
    LCD.cpp

    Code:
    #include "LCD.h"
    
    LCD::LCD(I2CAdapter* i2cAdapter)
    {
        this->i2cTransmitter = new I2CTransmitter(i2cAdapter);
        
        this->writeCommand(0x33);
        this->writeCommand(0x32);
        this->writeCommand(0x28);
        this->writeCommand(0x0E);
        this->writeCommand(LCD_CLEARDISPLAY);
        this->writeCommand(0x06);
        this->writeCommand(LCD_FORCE_CURSOR_FIRST_LINE);
        
    }
    
    ...
    LCDTransmitter.h

    Code:
    class LCDTransmitter : public Writable
    {
        private:
            I2CAdapter* i2cAdapter;
            uint8_t adapterOutputPort;
        
        public:
            LCDTransmitter(I2CAdapter* i2cAdapter);
            int8_t writeBytes(uint8_t* buffer, uint8_t length);
            int8_t writeCommand(uint8_t command);
            int8_t setCursor(uint8_t x, uint8_t y);
        
        public:
            int8_t writeByte(uint8_t byte, const uint8_t MODE);
            void checkIfBusy();
    };
    LCDTransmitter.cpp
    Code:
    LCDTransmitter::LCDTransmitter (I2CAdapter* newI2cAdapter) : i2cAdapter (newI2cAdapter) { }
    
    ...
    main.cpp
    Code:
    #include <avr/io.h>
    #include <string.h>
    #include "LCD.h"
    #include "I2CAdapter.h"
    #include "LCDTransmitter.h"
    #include "SerialPort.h"
    #include "I2CPort.h"
    #include "util/delay.h"
    
    int main(void)
    {
        I2CPort i2cPort;
        I2CAdapter i2cAdapter(&i2cPort);
        LCDTransmitter lcdTransmitter(&i2cAdapter);
        //SerialPort Serial;
    
        //Serial.open(9600, 0);
        
        while (1)
        {    
            lcdTransmitter.writeByte('A', MODE_DATA);
        }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,617
    You seem to be mixing up I2CTransmitter and LCDTransmitter.

    LCDTransmitter has a constructor taking I2CAdapter*

    But you didn't post any of I2CTransmitter .cpp/.h to see what you may (or may not) have overloaded.
    The compiler doesn't think you have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    92
    @Salem thank you.I didn't even notice it, you are right I mixed up I2CTransmitter and LCDTransmitter classes. I thought all the time that I used LCDTransmitter but instead I wrote I2CTrasnmitter... I knew it must be something stupid, anyways I was using adapter pattern so names got me kinda confused. LCD is a user, LCDTransmitter is a target, I2CAdapter is a adapter (obivously) and I2CPort is a adaptee.

    Thank you once again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. constructor problem
    By stewie griffin in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2009, 02:13 PM
  2. Problem with constructor?
    By KoshiB in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2006, 09:24 PM
  3. Constructor problem
    By rebel in forum C++ Programming
    Replies: 22
    Last Post: 01-11-2006, 06:45 AM
  4. Constructor problem
    By Orborde in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2005, 10:41 PM
  5. Problem with constructor re-definition
    By xErath in forum C++ Programming
    Replies: 4
    Last Post: 07-06-2004, 11:57 PM

Tags for this Thread