sksingh73
1st July 2010, 13:12
in my program, i have 2 cpp & their 2 header files. i want to access variable from one cpp file to other. There is no problem when i access int variable, but when i try to access quint32 variable, its value is not the same which is there in original cpp file. my code is
//hash.h
public:
hashchain(QWidget *parent = 0);
quint32 initial_key, session_key; //variable originally declared here
int num;
//hash.cpp
void hashchain::display()
{
quint32 unum[10];
int i;
for(i=0;i<10;i++)
unum=0;
ifstream in("session", ios::in|ios::binary);
in.read((char *)&unum, sizeof(unum));
initial_key = unum[9];
session_key = unum[8]; //value session_key defined here
//comn.h
#include "hash.h"
private:
hashchain *hashch;
quint32 sessionkey;
int val;
//comn.cpp quint32 session_key being accessed from this file
void comn::display_mac()
{
hashch = new hashchain(this);
sessionkey = hashch->session_key; //declaration here
val = hashch->num;
qDebug() << "Session key: " << sessionkey; //value being displayed here is not same as in hash.cpp, above
qDebug() << "num: " << val;
}
//hash.h
public:
hashchain(QWidget *parent = 0);
quint32 initial_key, session_key; //variable originally declared here
int num;
//hash.cpp
void hashchain::display()
{
quint32 unum[10];
int i;
for(i=0;i<10;i++)
unum=0;
ifstream in("session", ios::in|ios::binary);
in.read((char *)&unum, sizeof(unum));
initial_key = unum[9];
session_key = unum[8]; //value session_key defined here
//comn.h
#include "hash.h"
private:
hashchain *hashch;
quint32 sessionkey;
int val;
//comn.cpp quint32 session_key being accessed from this file
void comn::display_mac()
{
hashch = new hashchain(this);
sessionkey = hashch->session_key; //declaration here
val = hashch->num;
qDebug() << "Session key: " << sessionkey; //value being displayed here is not same as in hash.cpp, above
qDebug() << "num: " << val;
}