object oriented programming with C++?
I am looking to do a similiar thing in C++ as in java. In java, each object is in its own file. Let say I have three ojects: A, B, and C. Object A is an abstract class. In java, I could import file A as a library. Then, I could have object B inherit from object A and add new functionality to it. Also, I could have object C be a composite class and instantiate an instance of ojbect B. I want each class to be in a separate binary file, so I could use it as a library. Is this possible to do in c++? If so, what is this called, and where can I get more information on this. This is similiar to a DLL, but I think a DLL could only make procedures visible outside of the DLL. I want to make the class visible outside the DLL, so I can inherit its methods and attributes. How can this be done?
Hi!
All the things you described (inheritance, specialisation, encapsulation, composite classes) are possible in C++. the equivelant of the import statement in java is most probably #include. You can also use #pragma to specify lib info for link.
Allow me to demonstrate inheritance:
class A
{
private:
int m_a; // two member variables
float m_b;
public:
A(); // constructor
// put in getters, setters, whatever
}
to derive a class from A, simply:
class B : public A
{
// whatever
}
B now has access to anything declared public in A.
Im not entirely sure about binaries and DLL's though.
Have a look at cplusplus.com for some more details.
Hope this helps!
[edited by - Juggers on July 25, 2003 2:44:07 AM]
All the things you described (inheritance, specialisation, encapsulation, composite classes) are possible in C++. the equivelant of the import statement in java is most probably #include. You can also use #pragma to specify lib info for link.
Allow me to demonstrate inheritance:
class A
{
private:
int m_a; // two member variables
float m_b;
public:
A(); // constructor
// put in getters, setters, whatever
}
to derive a class from A, simply:
class B : public A
{
// whatever
}
B now has access to anything declared public in A.
Im not entirely sure about binaries and DLL's though.
Have a look at cplusplus.com for some more details.
Hope this helps!
[edited by - Juggers on July 25, 2003 2:44:07 AM]
thanks for replying. Yeah, I know c++ supports inheritance, specialisation, encapsulation, and composite classes. If I compile the example you showed, then the c++ compiler would create one executable. I took a couple c++ classes in school before, but every program I wrote was a single binary executable file. I want to know a way to break it up into multiple binary files. I also know that I could break an application into multiple binary files using DLLs and and executable files. But using DLL seems like a procedural approach since I can only make procedures visible outside of the DLL. I want to know an object oriented approach where I can have one binary file create an object that is derived from another object contained in a different binary file(similiar to how Java does it). If it is not possible, then please say so. Thanks.
[edited by - samdiep on July 25, 2003 3:14:31 AM]
[edited by - samdiep on July 25, 2003 3:14:31 AM]
mmhh... with java, you haven't got binary files as .exe, you just have .class. The .class are objects, and with c++ you can make an object file (.o) for each class. Is that what you mean ? The .exe is generated when you link your objects (.o).
------------------------
- Seby -
www.dfhi-bomber.fr.st
[edited by - theSeby on July 25, 2003 5:26:04 AM]
c++ java file.h file.java file.cpp | | | (compilation) V V file.o file.class | | (link edit) V file.exe
------------------------
- Seby -
www.dfhi-bomber.fr.st
[edited by - theSeby on July 25, 2003 5:26:04 AM]
------------------------ - Seby -www.dfhi-bomber.fr.st
And also, you can make the class exportable from a DLL. So if you had a class YourClass in the dll you can just #include the header files that include the information in the dll and then simply
class MyOtherClass : YourClass
{
};
or simply instantiate YourClass* myClass = new YourClass;
etc..
Look up making a DLL on flipcode.com
class MyOtherClass : YourClass
{
};
or simply instantiate YourClass* myClass = new YourClass;
etc..
Look up making a DLL on flipcode.com
------------------------------------------------------
50% of me is a huge nerd! How about you?
50% of me is a huge nerd! How about you?
As gommo said, the C++ equivalent is to include the header file. You can hide your implementation in a binary, but to have someone linking against your code you must at least have the prototypes open. So you can have your class A''s implementation in a library, and when you want to have class B inherit from A, you will need to #include a header describing A, and link against the library containing the implementation.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement