|
From: Steve B. <iac...@no...> - 2003-01-07 18:56:50
|
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
|