Connecting Tech Pros Worldwide Forums | Help | Site Map

undefined reference to ,vtable for...

Newbie
 
Join Date: Feb 2009
Posts: 2
#1: Feb 26 '09
Hi,

I'm trying to implement factory method pattern using C++ on Ubuntu 8.04 using gcc 4.2.

There are 3 major classes DBConnectionFactory, DBConnector and OracleConnector (which is the derived class of DBConnector).

source in separate header and cpp files as below.


/* DBConnectionFactory.h */

#ifndef _DBCONNECTIONFACTORY_H
#define _DBCONNECTIONFACTORY_H
#include <iostream>
#include "DBConnector.h"
using namespace std;

class DBConnectionFactory
{
public:
static DBConnector* getConnector(string&);
};

#endif /* _DBCONNECTIONFACTORY_H */

//================================================== ==========

/* DBConnectionFactory.cpp */

#include "DBConnectionFactory.h"
#include "DBConnector.h"
#include "OracleConnector.h"

DBConnector* DBConnectionFactory::getConnector(string& dbName)
{
DBConnector* factory;

if(dbName=="oracle"){
factory = new OracleConnector();
}
else{
exit(1);
}
if(factory==0){
exit(1);
}
else{
return factory;
}
}

//================================================== ==========

/* DBConnector.cpp */

#ifndef _DBCONNECTOR_H
#define _DBCONNECTOR_H
#include <iostream>
using namespace std;

class DBConnector
{
public:
// Pure virtual methods. Derived class(es) should implement these methods
virtual void init() = 0;
virtual void connect() = 0;
virtual void shutdown() = 0;

virtual ~DBConnector()
{

}
};

#endif /* _DBCONNECTOR_H */


//================================================== ==========

/* OracleConnector.h */

#ifndef _ORACLECONNECTOR_H
#define _ORACLECONNECTOR_H
#include <iostream>
#include "DBConnector.h"
#include <occi.h>

using namespace std;
using namespace oracle::occi;

class OracleConnector : public DBConnector
{
private:
// commented...

public:
void init();
void connect();
void shutdown();
};

#endif /* _ORACLECONNECTOR_H */

//================================================== ==========

/* OracleConnector.cpp */

#include <iostream>
#include "OracleConnector.h"

using namespace std;

void OracleConnector::init(){
// code...
}

void OracleConnector::connect(){
// code...
}

void OracleConnector::shutdown(){
// code...
}

int main(){} // TODO: Remove this main() added for testing

When I try to compile DBConnectionFactory.cpp it gives folowing error(s).

Command: g++ DBConnectionFactory.cpp -I/opt/oracle/include -L/opt/oracle/lib -locci -lclntsh

Error:

/tmp/cc15eWsy.o: In function `OracleConnector::OracleConnector()':
DBConnectionFactory.cpp:(.text._ZN15OracleConnecto rC1Ev[OracleConnector::OracleConnector()]+0x16): undefined reference to `vtable for OracleConnector'
collect2: ld returned 1 exit status

I went through GCC FAQs but could not figure out the reason. Highly appreciate your feedback.

Thanks,

Chatura

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,375
#2: Feb 26 '09

re: undefined reference to ,vtable for...


This compiles fine with Visual Studio.NET 2008.
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 385
#3: Feb 26 '09

re: undefined reference to ,vtable for...


You don't link OracleConnector.o with your DBConnectionFactory, but reference OracleConnector in it when create it
factory = new OracleConnector();

It compiles ok if you merge all this stuff in one cpp file.
Newbie
 
Join Date: Feb 2009
Posts: 2
#4: Feb 27 '09

re: undefined reference to ,vtable for...


Thanks for replying... I will try
Reply

Tags
c++, factory pattern, occi, oracle, vtable