|
From: Goran K. <go...@vo...> - 2003-01-08 00:20:42
|
this one missed the list,
sorry
----- Original Message -----
From: Goran Kavrecic <go...@vo...>
To: Steve Bertrand <iac...@no...>
Sent: Tuesday, January 07, 2003 9:41 PM
Subject: Re: [Dev-C++] using 2 .c files
> Maybe I made a fast judgement, but I think:
> the problem is "there" because the main.c hasn't "seen" the decalaration
of
> CServer
>
> So, I would:
> - move the class definition to myheader.h
> > class CServer {
> > int var1;
> > int var2;
> > string var3;
> > string var4;
> >
> > void addServer(int, string, string);
> > }
>
> - define the extern in server.c or even in .h
> > extern CServer *server; // The problem should be gone
>
> Regards,
> Goran
>
> ----- 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:
> >
> > -----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---------
> >
> > 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
>
|