I have setup a class that stores the data for my database connections. Inside the class I have several members that either set or get the variables.
Inside my main I have set the value of the hostname. Now I have a second class that I am testing with called TestClass. What I am trying to do is access the value that the main method set inside of my TestClass.
Here is the current code I am testing with.
I am not an expert in c++, and i am trying to better educate myself. I took the over all concept from something I would use in as3.
Any help with this would be greatly appreciated.
mainTest.cpp
int main()
{
Config cfg;
DbConfig dbcfg;
TestClass tclss;
try
{
/* Load the configuration.. */
cout << "loading [config.cfg]..";
cfg.readFile("config.cfg");
cout << "ok" << endl;
string hostname = cfg.lookup("application.live.hostname");
dbcfg.setDatasource(hostname.c_str());
cout << dbcfg.getDatasource() << endl;
tclss.testDSource();
cout << "Done!" << endl;
}
catch (...)
{
cout << "failed" << endl;
}
return 0;
}
DbConfig.cpp
#include "DbConfig.h"
#include <string>
#include <iostream>
DbConfig::DbConfig(){}
void DbConfig::setDatasource(const char* dSource){
datasource = dSource;
}
const char* DbConfig::getDatasource(void){
return (datasource);
}
TestClass.cpp
TestClass::TestClass() {}
void TestClass::testDSource(){
DbConfig dbcfg;
std::cout << "DATASOURCE : " << dbcfg.getDatasource() << std::endl;
}