LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2006, 01:30 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
Really Really simple problem


#include <iostream>
#include <list>
#include <db_cxx.h>

using namespace std;

class Subject;

class Observers
{
public:
virtual ~Observers();
virtual void Update (Subject *theChangedSubject) = 0;
protected:
Observers() { }
};

class Subject {
public:
virtual ~Subject() { }
virtual void Attach(Observers *);
virtual void Detach(Observers *);
virtual void Notify(void);
protected:
Subject() { }
private:
list<Observers *>*m_Observers;

};


class RS232_Controller : public Subject
{
public:
RS232_Controller() { }
public:
~RS232_Controller() { }
void Attach (Observers *);
void Detach (Observers *);
void Notify (void);
};

int main (int argc, char *argv[])
{
RS232_Controller *rs232;

rs232 = new RS232_Controller();
return 0;
}

///////////////////////
Compiled with
g++ -o subjecttest subjecttest.cpp -ldb

///////////////////////
Errors returned
[root@localhost subject]# g++ -o subject subjecttest.cpp -ldb
subjecttest.cpp:49:2: warning: no newline at end of file
/tmp/ccpfDV9p.o(.gnu.linkonce.t._ZN7SubjectD2Ev[Subject::~Subject()]+0x7): In function `Subject::~Subject()':
subjecttest.cpp: undefined reference to `vtable for Subject'
/tmp/ccpfDV9p.o(.gnu.linkonce.t._ZN7SubjectC2Ev[Subject::Subject()]+0x4): In function `Subject::Subject()':
subjecttest.cpp: undefined reference to `vtable for Subject'
/tmp/ccpfDV9p.o(.gnu.linkonce.t._ZN16RS232_ControllerC1Ev[RS232_Controller::RS232_Controller()]+0x16): In function `RS232_Controller::RS232_Controller()':
subjecttest.cpp: undefined reference to `vtable for RS232_Controller'
collect2: ld returned 1 exit status
[2]+ Done kedit subjecttest.cpp


A Stereotype newbie question for Linux
Thanks
J
 
Old 03-13-2006, 01:53 AM   #2
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
And this one too
/////////////////////////////

[root@localhost dltest]# g++ -o dltest dltest.cpp
dltest.cpp:27:2: warning: no newline at end of file
dltest.cpp: In function ‘int main(int, char**)’:
dltest.cpp:18: error: invalid conversion from ‘void*’ to ‘void (*)()’
[1]+ Done kedit dltest.cpp




/////////////
#include <dlfcn.h>
#include <iostream>

typedef void (*demo_function)(void);

int main (int argc, char *argv[])
{
const char *error;
void (*module);
demo_function demo1;

module = dlopen ("libhello.so", RTLD_LAZY);
if (!module) {
fprintf (stderr, "Couldn't open libhello.so: %s\n", dlerror());
exit(-1);
}

demo1 = dlsym (module, "hello");
if ((error = dlerror())) {
fprintf (stderr, "Couldn't find hello: %s\n", error);
exit (-1);
}

(*demo1)();

return 0;
}
 
Old 03-13-2006, 02:09 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,724

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
Please:
- use a meaningful thread title
- edit your previous postings, and enclose your code samples with "code" tags.
 
Old 03-13-2006, 03:40 AM   #4
bc8o8
Member
 
Registered: Jun 2003
Location: Boston, MA
Distribution: Debian
Posts: 57

Rep: Reputation: 15
jilliagre is right, using code tags makes it a LOT easier to read what you're doing, and the title "Really really simple problem" doesn't really tell anything about what your problem is (i.e. you won't get many responses).

Anyway, your first problem is a result of not having defined you methods within both the "Subject" and "RS232" classes. You have declarations but no definitions. If you want to make a method abstract (in Subject) you can just say
Code:
virtual void Attach(Observers *) = 0;
but then you MUST define it within any and all subclasses before you can use them. Also note that you cannot instanciate a class with an abstract method.

And your second problem should be solved by replacing
Code:
demo1  = dlsym (module, "hello");
with
Code:
*(void **)(&demo1)  = dlsym (module, "hello");
This puts your return value (demo1) in the right format to receive the function as a (void *)
 
Old 03-13-2006, 04:05 AM   #5
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Thanks everyone
And The quality of the posting will be improved next time

Jack
 
Old 03-13-2006, 04:08 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,724

Rep: Reputation: 434Reputation: 434Reputation: 434Reputation: 434Reputation: 434
Why not doing it right now ?
Your own previous postings are editable by you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet another problem, but this one is simple! Taigrr Linux - Newbie 7 02-02-2006 08:04 PM
simple C++ Problem :) indian Programming 2 02-28-2005 10:42 AM
Help....Simple problem hkstandard Mandriva 1 09-20-2004 06:03 AM
SImple problem??? jlatzer Linux - Networking 5 06-27-2003 04:42 PM
Simple problem with .... FredrikN Linux - Networking 1 10-27-2002 06:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration