I am having a problem with my program where in I declared the variable from a header file and execute it on a CPP file. I am getting an error whi开发者_StackOverflowch is the undefined reference to the variable.
here a sample code of my project:
CPP FILE
#include "function.h"
CClass::CClass() : m_Db(HOST,USER,PASSWORD,DATABASE)
{
...
}
HEADER FILE
#ifndef CONNECTION_H
#define CONNECTION_H
#include "crypt.h"
extern CCrypt *c_crypting;
#define HOST c_crypting->Decrypt_Host()
#define USER c_crypting->Decrypt_Username()
#define PASSWORD c_crypting->Decrypt_Password()
#define DATABASE c_crypting->Decrypt_Database()
#endif // DBCONNECTION_H
if i run this code I get an error of "undefined reference to 'c_crypting'"
This line in your header file:
extern CCrypt *c_crypting;
does not create a c_crypting
pointer. It only says "one of my code modules will have a pointer to CCrypt that is called c_crypting" so that the other code files can use that. You'll need to have something like:
CCrypt *c_crypting; // possibly '= 0;'
in one of your .cpp
files, and initialize it properly somewhere.
精彩评论