|
|
Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » Link error when using polymorphism
Link error when using polymorphism [message #15669] |
Sat, 03 May 2008 20:14  |
lucpolak
Messages: 18 Registered: April 2008 Location: France
|
Promising Member |
|
|
Hi all,
i'm Lucas and i'm new in using TheIDE. I have a problem.
I have an abstract class named DBConnector and a derived class MySqlConnector.
When compiling, all is ok but i always have the link error :
vtable for VirtualSofts::SQL::DBConnector(referenced from d:\ultimate++\out\easybat\mingw.debug_full.gui.main.noblitz\ erpsystem.o:290; .text$_ZN12VirtualSofts3SQL11DBConnectorC2Ev; Vir
tualSofts::SQL::DBConnector::DBConnector(void); VirtualSofts::SQL::DBConnector::DBConnector())
I've tried to declare a constructor for DBConnector but the problem persists.
Here the code of DBConnector :
namespace VirtualSofts
{
namespace SQL
{
class DBConnector
{
protected:
bool m_Connected;
String m_errorState;
public:
virtual ~DBConnector()
{
Disconnect();
}
//------------------------------------------
// Accès à la base
//------------------------------------------
virtual bool Connect(String db);
virtual bool Disconnect();
//------------------------------------------
// Accesseurs
//------------------------------------------
inline bool IsConnected() const { return m_Connected; }
//------------------------------------------
// Exécution de requêtes
//------------------------------------------
virtual int SQLExecDML(const String &request);
virtual cResultSet SQLExecQuery(const String &request);
//------------------------------------------
// Gestion des Erreurs
//------------------------------------------
String GetLastError() const {return m_errorState;}
};
}
}
and here the code of MySQLConnector :
namespace VirtualSofts
{
namespace SQL
{
class MySQLConnector: public DBConnector
{
//...
public:
//------------------------------------------
// Accès à la base
//------------------------------------------
virtual bool Connect(String db);
virtual bool Disconnect();
//------------------------------------------
// Exécution de requêtes
//------------------------------------------
virtual int SQLExecDML(const String &request);
virtual cResultSet SQLExecQuery(const String &request);
};
}
}
The problem appears when i instantiate the object by this way :
DBConnector *dbcnx = new MySQLConnector();
The code is ok ?
If i not use the virtual functions, all is ok...
Thanks for help ^^,
Lucas
[Updated on: Thu, 23 December 2010 14:48] Report message to a moderator
|
|
|
|
|
Re: Link error when using polymorphism [message #15680 is a reply to message #15676] |
Sun, 04 May 2008 12:42   |
bytefield
Messages: 210 Registered: December 2007
|
Experienced Member |
|
|
At me, your code work well.
I provide bellow a test package.
You may specify which platform, compiler and u++ version you use.
(Ubuntu 8.04, u++ SVN.219(built on Ubuntu 7.10), g++ compiler)
Compiler version:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
-
Attachment: SQLPoly.zip
(Size: 1.52KB, Downloaded 334 times)
cdabbd745f1234c2751ee1f932d1dd75
[Updated on: Sun, 04 May 2008 14:27] Report message to a moderator
|
|
|
|
Re: Link error when using polymorphism [message #15693 is a reply to message #15691] |
Sun, 04 May 2008 20:33   |
bytefield
Messages: 210 Registered: December 2007
|
Experienced Member |
|
|
Well, there are some problems.
You forgot to implement some functions
bool DBConnector::Disconnect()
{
}
bool DBConnector::Connect(String db)
{
}
int DBConnector::SQLExecDML(const String &request)
{
}
cResultSet DBConnector::SQLExecQuery(const String &request)
{
}
if you put these functions in DBConnector.cpp all thing goes normally, and program compiles without errors.
I've commented out
//#include <Toolkit/Tools.h>
//using namespace VirtualSofts::Tools;
in every file, because you didn't provided that package, and also included in your project Core package if you want to use u++ Strings.
The program compiles well, but there are memory leaks and guess that is because you mix Ultimate++ code (String which is moveable and implement pick concept) with std containers which use deep copy concept. So you should use U++ containers or use std::string with std containers instead of Upp::String with std containers.
As suggestion: never mix Ultimate++ with STL and use case sensitive package name, because it matter on Linux platform.
( you provided MySQLconnector instead of MySQLConnector)
P.S.: SQL is implemented in Ultimate++ so you may use it if you need.
Edit: it didn't implement a polymorphic type.
Andrei
-
Attachment: SQLTest.zip
(Size: 4.60KB, Downloaded 319 times)
cdabbd745f1234c2751ee1f932d1dd75
[Updated on: Sun, 04 May 2008 20:36] Report message to a moderator
|
|
|
Re: Link error when using polymorphism [message #15694 is a reply to message #15693] |
Sun, 04 May 2008 21:06  |
lucpolak
Messages: 18 Registered: April 2008 Location: France
|
Promising Member |
|
|
Thanks, it's works,
I've not implement the missing functions because these are virtuals methods. I've passed its as pure virtual methods and the linking is ok.
The project is initially coded with VS6.0 and a lot of source code is original. I've not finished to migrate it to UPP. Thanks for the explications between the two env.
Lucas
|
|
|
Goto Forum:
Current Time: Mon Apr 28 19:23:39 CEST 2025
Total time taken to generate the page: 0.00651 seconds
|
|
|