Thread: RE: [Dev-C++] Base classes....
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Mat...@Ve...> - 2005-05-31 16:20:43
|
Well my advice to you would be to start with the simplest possible code, and
then work up to the complicated version. Also, when working with classes, it
helps to draw some kind of simple paper diagram. At my desk, I have posted
the diagrams of the <ios> hierarchy and the <stdexcept> hierarchy for
example.
Here would be some really trivial multi-class code. Note how you can catch a
runtime_error as an exception because runtime_error is based on exception.
If you look at the stdexcept system header or the docs for this header, you
can see how this works in more detail.
Also, google "C++ polymorphism" as well.
HTH!
Matt
#include <stdexcept>
#include <iostream>
using namespace std;
int main(int argc, char* argv)
{
try
{
throw runtime_error("foo");
}
catch (const exception& e)
{
cout << e.what();
return 1;
}
return 0;
}
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Sabree
Blackmon
Sent: Friday, May 27, 2005 5:52 PM
To: Dev-C++ Mailing List
Subject: [Dev-C++] Base classes....
Hello all,
I am making a plugin manager that loads dll's and stores pointers to the
imported classes in vector so users can request the classes when ever during
the program. However the problem lies in the fact that vectors or arrays can
only store one type of object in other words one type of class pointer which
will not work. I know that a base class pointer is compatible with a derived
class. I was thinking about creating a base class where all plugin classes
are derived from. I know this is possible because Crystal Space 3d uses the
same technique. I'm just not sure how. I've included the file where the base
class in Crystal Space is declared. Maybe someone can make some sense of it
all. I tried to reduce the file size, so if anyone need the rest just say
so. Thanks.
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|
|
From: <Mat...@Ve...> - 2005-06-01 00:42:57
|
Doesn't he want a class that is a pointee of some pointer, not a class containing a pointer to some other pointee? The best educational video in all of computer science: http://cslibrary.stanford.edu/104/ ;-) Matt -----Original Message----- From: Robert Alatalo [mailto:ral...@gm...] Sent: Tuesday, May 31, 2005 5:38 PM To: Mat...@ve... Cc: sab...@ve...; dev...@li... Subject: Re: [Dev-C++] Base classes.... But more generally... look at ALL the information that you need to store and think you might need to store and start thinking about the relationships.. and compare the 'is a' with the 'has a' Do you want a class that has a pointer or a class that is a pointer? ___________________________________________________________________ The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. |
|
From: Robert A. <ral...@gm...> - 2005-06-01 00:38:48
|
I would go one step further and suggest you look at the information
you want to store.
You want to store pointers to some data... but the data is different
enough that you are looking at some type of abstraction. What other
type of information do you want to store? I'm speculating that you
may want to store some additional information about the classes..like
maybe the class name, maybe a description. So it sounds like you may
have the makings of a pointer_to_dll class. This class would/could
have enough additional information (look at runtime information cause
I know it exists but don't recall the details) such that you could
store a pointer to void and cast it as required.
But more generally... look at ALL the information that you need to
store and think you might need to store and start thinking about the
relationships.. and compare the 'is a' with the 'has a' Do you want
a class that has a pointer or a class that is a pointer?
On 5/31/05, Mat...@ve...
<Mat...@ve...> wrote:
> Well my advice to you would be to start with the simplest possible code, =
and
> then work up to the complicated version. Also, when working with classes,=
it
> helps to draw some kind of simple paper diagram. At my desk, I have poste=
d
> the diagrams of the <ios> hierarchy and the <stdexcept> hierarchy for
> example.
>=20
> Here would be some really trivial multi-class code. Note how you can catc=
h a
> runtime_error as an exception because runtime_error is based on exception=
.
> If you look at the stdexcept system header or the docs for this header, y=
ou
> can see how this works in more detail.
>=20
> Also, google "C++ polymorphism" as well.
>=20
> HTH!
> Matt
>=20
>=20
> #include <stdexcept>
> #include <iostream>
>=20
> using namespace std;
>=20
> int main(int argc, char* argv)
> {
> try
> {
> throw runtime_error("foo");
> }
>=20
> catch (const exception& e)
> {
> cout << e.what();
> return 1;
> }
>=20
> return 0;
> }
>=20
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of Sabree
> Blackmon
> Sent: Friday, May 27, 2005 5:52 PM
> To: Dev-C++ Mailing List
> Subject: [Dev-C++] Base classes....
>=20
>=20
> Hello all,
> I am making a plugin manager that loads dll's and stores pointers to =
the
> imported classes in vector so users can request the classes when ever dur=
ing
> the program. However the problem lies in the fact that vectors or arrays =
can
> only store one type of object in other words one type of class pointer wh=
ich
> will not work. I know that a base class pointer is compatible with a deri=
ved
> class. I was thinking about creating a base class where all plugin classe=
s
> are derived from. I know this is possible because Crystal Space 3d uses t=
he
> same technique. I'm just not sure how. I've included the file where the b=
ase
> class in Crystal Space is declared. Maybe someone can make some sense of=
it
> all. I tried to reduce the file size, so if anyone need the rest just sa=
y
> so. Thanks.
> ___________________________________________________________________
> The information contained in this message and any attachment may be
> proprietary, confidential, and privileged or subject to the work
> product doctrine and thus protected from disclosure. If the reader
> of this message is not the intended recipient, or an employee or
> agent responsible for delivering this message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly prohibited.
> If you have received this communication in error, please notify me
> immediately by replying to this message and deleting it and all
> copies and backups thereof. Thank you.
>=20
>=20
>=20
> -------------------------------------------------------
> This SF.Net email is sponsored by Yahoo.
> Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
> Search APIs Find out how you can build Yahoo! directly into your own
> Applications - visit http://developer.yahoo.net/?fr=3Doffad-ysdn-ostg-q22=
005
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|