Em có lớp thế này:
Code:
//test.cpp
#include "stdafx.h"
void test::func1 ()
{
a = 100;
SetTimer (0, 0, 1000, (TIMERPROC) func3);
};
void test::func2 (FUNC func)
{
func();
};
void test::func3 ()
{
MessageBox (0, (const char*)a, 0, MB_OK);
};
//test.h
Code:
#ifndef TEST_H
#define TEST_H
#include "stdafx.h"
typedef void (CALLBACK *FUNC)();
class test
{
static BYTE a;
public:
void func1 ();
void func2 (FUNC func);
static void func3 ();
};
#endif
//Chương trình chính
Code:
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
test t;
t.func1 ();
MessageBox (0, 0, 0, MB_OK);
return 0;
}
em muốn 1 hàm trong lớp sử dụng hàm khác trong lớp đó làm tham số callback nhưng ko được, đọc trên mạng thấy hàm callback phải là static nên cho vào. Nhưng dịch lại ra lỗi này:
Compiling...
test.cpp
Linking...
test.obj : error LNK2001: unresolved external symbol "private: static unsigned char test::a" (?a@test@@0EA)
Debug/testc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Ai biết cách giải quyết ko nhỉ ???