Hi,
I am new to c++, facing difficulty in compiling the following code
#include <iostream>
#include<string.h>
using namespace std;
class myclass {
public:
int i, j, k, *l; // accessible to entire program
static int *m;
};
int myclass::*m = NULL;
int main()
{
myclass a, b, *p;
a.i = 100; // access to i, j, and k is OK
a.j = 4;
a.k = a.i * a.j;
b.k = 12; // remember, a.k and b.k are different
p = &b;
*b.l = 23;
*b.m = 23;
//memcpy(&b.m, &b.l, sizeof(int));
cout << "with ptr = " << *b.l << *(p->l) <<endl;
cout << a.k << " " << b.k << endl;
return 0;
}
in the above code i can access value of l very easily, for testing purpose i declared m as static, as static variable have to be defined outside the class i am doing it like "int myclass::*m = NULL;", but when i try to access the value of m (*b.m = 23;) I get error following error in the compilation.
g++ ptr1.cc
/tmp/cc1L6oUM.o: In function `main':
ptr1.cc:(.text+0x45): undefined reference to `myclass::m'
collect2: ld returned 1 exit status
can anyone tell me where I am wrong?
Is there any thing wrong in defining static variable? or is there anything wrong in accessing the value?
Your help would be appreciable. Thanks in advance.