|
From: Wobien <wo...@pl...> - 2003-01-07 22:46:42
|
----- Original Message -----
From: "Steve Bertrand" <iac...@no...>
To: <dev...@li...>
Sent: Tuesday, January 07, 2003 7:55 PM
Subject: [Dev-C++] using 2 .c files
> Hi there, this is my first post, so please forgive me if my message is
> out of context for this list.
>
> I am building an application in c++ on freebsd, and can't get 2 .c files
> to merge properly. When I compile, I get 'undefined CServer' when I
> compile. I tried defining the 'server' variable with extern, but I don't
> know if I was using extern in the proper context. For instance, here are
> snippets of the 2 files:
>
Each file you make must have the definitions of all the objects you use in
it.
Your file main.cc uses the class CServer, but it does not have a definition
of it.
You can put the declaration of class CServer in a header file and include
that header file in server.cc and in main.cc
> -----snip server.cc--------
>
> #include "myheader.h"
>
> class CServer {
> int var1;
> int var2;
> string var3;
> string var4;
>
> void addServer(int, string, string);
> }
>
> void CServer::addServer(int a, string b, string c) {
>
> var3 = c;
> var4 = b;
> var3 = a;
> }
>
> --------end snip server.c-----------
>
> ------snip main.cc-----------
>
> void main() {
>
> CServer *server; // The problem is here.
> server = new CServer;
>
> server.addServer(feedvar, feedvar, feedvar);
>
> /* Do some other stuff */
>
> ----------end snip main.cc---------
>
I do´nt understand exactly what your second problem is, but I think it might
be that
server.cc does not have the object db_connection you define in main.cc
You can try to add in server.cc:
extern Connection db_connection;
before you work with the connection.
Wobien
> Another problem: In this same program, I would like main.cc to connect
> to a mysql database early in main(), then allow the server.cc file (more
> specifically, the member functions of CServer) to read/write to the db.
> I know the mysql syntax is correct, as when I put all of the code in
> one file, everything works ok. Is this another extern problem? What
> part of the mysql code to I have to initialize with extern and where?
> Example:
>
> main.c------
>
> // all of the mysql db stuff defined and included in 'myheader.h'
> #include "myheader.h"
>
> main() {
>
> Connection db_connection;
> db_connection.connect(//send db info here)
>
> end snip main.c----------
>
> Eventually, the server.c file opens up a table, then does it's thing,
> but when compiling, it seems as though the database connection doesn't
> even exist (from the point of view of server.c).
>
> What is the easiest way to link these 2 files so they merge and appear
> as one? Or is that the purpose of extern? I simply want to divide up
> my code so I can have 'modules' written in each .c file to make it
> easier to maintain.
>
> Thanks for any help in advance.
>
> Steve Bertrand
>
>
>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> http://www.vasoftware.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|