开发者

Undefined reference of header variable in Qt C++

开发者 https://www.devze.com 2023-03-11 05:40 出处:网络
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 th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消