|
From: Abhijit S. <mu...@gm...> - 2002-09-26 16:42:07
|
----- Original Message -----
From: Santiago
To: Dev...@li...
Sent: Wednesday, September 25, 2002 11:41 PM
Subject: [Dev-C++] classes help
Does anyone know how to link an implementation file (ie: Myclass.C) with a
client code (ie: usingClasses.C) so they can use my own Myclass.h header
file?
This is weird, I tried doing it in a G++ compiler on a solaris unix terminal
at school and it worked. However, the same exact code didn't work in
Dev-cpp. I know there are other options like console application or empty
project and I don't know how to use those.
Please let me know the correct way to link an implementation and a client
code so they can use my own defined class.
Thank you very much.
Santiago
--------------------------------
Greets, Santiago.
This is the general layout I use:
Interface file, only declarations: class.h
Implementation file, only definitions: class.cpp
Client file(s) that use the class: test.cpp
<class.h>
// Prevent re-entry
#ifndef __CLASS_H
#define __CLASS_H
#include <what_foo_needs.h>
class foo
{
public:
foo();
foo(int);
foo(int, int);
~foo();
protected:
int apples;
int oranges;
};
#endif // __CLASS_H
</class.h>
Note that the interface file has *no* implmentation whatsoever. It's
allegedly a good practise to keep them separate.
class.cpp will have the definitions, including the constructors and
destructors. It will include class.h.
The client files will #include class.h, and are then finally linked with
class.cpp (by adding class.cpp to the project/makefile/command-line.
You say that the code worked on Solaris, was it on GCC? If so, it should
work here also. Maybe the problem is syntactic (mismatched braces, missing
semicolon, etc.).
PS: Note that this is what I do. If you have any better ideas, let us know.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|