You are not logged in.

1

Tuesday, June 1st 2010, 11:28am

Multi-inheritance, compile error

I got the punish of Multi-inheritance, and I am already changing my design now, but just wanner know where is the wrong, it really sucks.

Background:
I building a communication class called "Talk" for exercise. It "is a" QWidget, but in order to get TCP/IP funtion, I let it "Is a" Socket too. The reason I use this bad way is because I'm not using QT's network library, so can't use signal/slots to handle the Socket's event, so I want to combine QWidget and Socket together forming a new class "Talk", overloading some Socket's virtual callback funtion to express itself in QWidget.

Question:
All seem ok except the the Non-QT object's constructor and destructor in Talk class:

Definition of the Talk class:
class Talk : public QWidget, public LoginSocket
{................}

This line is wrong in Talk's constructor:
Talk::Talk(ISocketHandler& h, QWidget *parent): QWidget(parent), ui(new Ui::Talk), LoginSocket(h)
{......}
/home/sunbin/QT-program/LanTalk/talk.cpp:5: undefined reference to `LoginSocket::LoginSocket(ISocketHandler&)'


And destructor wrong:
/home/sunbin/QT-program/LanTalk/talk.cpp:21: undefined reference to `LoginSocket::~LoginSocket()'

I have tested the Socket class "LoginSocket", no problem. Only question is in the "undefined reference to `LoginSocket::" .

Would you please help me, thanks.

This post has been edited 3 times, last edit by "Sun_Bin" (Jun 1st 2010, 2:03pm)


2

Tuesday, June 1st 2010, 2:01pm

undefined references to
'LoginSocket::LoginSocket(ISocketHandler&)'
'LoginSocket::~LoginSocket()'
are probably caused by not linking the module defining LoginSocket

3

Tuesday, June 1st 2010, 2:34pm

Thanks.
undefined references to
'LoginSocket::LoginSocket(ISocketHandler&)'
'LoginSocket::~LoginSocket()'
are probably caused by not linking the module defining LoginSocket
Then how to link the module.

4

Tuesday, June 1st 2010, 2:59pm

show your .pro file

5

Tuesday, June 1st 2010, 3:18pm

# -------------------------------------------------
# Project created by QtCreator 2010-06-01T08:26:11
# -------------------------------------------------
TARGET = LanTalk
TEMPLATE = app
SOURCES += main.cpp \
talk.cpp \
UserIp.cpp \
LoginSocket.cpp
HEADERS += talk.h \
UserIp.h \
Port.h \
LoginSocket.h
FORMS += talk.ui

6

Tuesday, June 1st 2010, 3:54pm

Thank you Sir Nicolas SOUCHON
I did not know anything about the ".pro" file before, when I need to include additional libraries, I just edit the Makefile directly, but edit the .pro file is obvious the better way. I add these lines in .pro:
INCLUDEPATH += /usr/local/include/Sockets
LIBS += -L/usr/local/lib \
-lSockets \
-lssl \
-lcrypto

Makefile regenerated automatically, and the compile succeeds.

Another thing, it's still wired about the question I met before: why when I add "-L/usr/local/lib ...." in the Makefile, header files including is OK, but the linking having problem. This is unimportant, anyway.

Thank you. :)