On May 15, 11:35 am, Zeppe
<zeppe@.remove.all.this.long.comment.email.itwrote :
mickey.marsh...@litepoint.com wrote:
What am I doing wrong?
you are not posting the code that doesn't work.
Regards,
Zeppe
Here is the sample code:
Main Code
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#include ".\testdlg.h"
#include ".\arithmetic.h"
..
..
..
void CtestDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
int rv;
InitAB();
CAddTwoNumbers Add2;
//CSubtract Sub2;
Arithmetic *ar1=&Add2;
//Arithmetic *ar2=&Sub2;
//ar= new Arithmetic;
ar1->EnterTwoNumbers(2,4);
//ar2->EnterTwoNumbers(8,4);
rv=Add2.Add ();
//rv=Sub2.Sub2 ();
}
Globals.h
#ifndef MYGLOBALS_H
#define MYGLOBALS_H
static int *a1; //this is the global variable
static int *b1; //this is the global variable
void InitAB();
#endif
globals.cpp
#include ".\globals.h"
void InitAB()
{
a1=new int;
b1=new int;
}
Master class (arithmetic.cpp)
#include "StdAfx.h"
#include ".\arithmetic.h"
//#include ".\globals.h"
//extern int a1,b1;
Arithmetic::Arithmetic(void)
{
}
Arithmetic::~Arithmetic(void)
{
}
void Arithmetic::EnterTwoNumbers(int a, int b)// this works fine
{
*a1=a;
*b1=b;
}
void Arithmetic::GetTwoNumbers(int * a, int * b)
{
if (NULL!=a)
if (NULL!=b)
{
*a=*a1;
*b=*b1;
}
}
inherited class
#include "StdAfx.h"
#include ".\arithmetic.h"
//#include ".\globals.h"
//extern int a1,b1;
CAddTwoNumbers::CAddTwoNumbers(void)
{
}
CAddTwoNumbers::~CAddTwoNumbers(void)
{
}
CAddTwoNumbers::Add(void)// a1 and b1 are both NULL here
{
return(*a1+*b1);
}