main.cpp
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
| #include <QtCore/QTimer>
#include <QtCore/QCoreApplication>
#include <QtCore/QLibrary>
#include <QtCore/QTextStream>
#include <windows.h>
typedef void (*func1)();
typedef void (*func2)(int);
typedef int (*func3)();
typedef bool (*func4)();
typedef void (*func5)();
typedef void (*func6)();
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QTextStream qout(stdout);
QLibrary m("m");
if(!m.load())
{
qout << "Couldn't open the library" << endl;
return 1;
}
func1 _CMyStack = (func1) m.resolve ("CMyStack");
if(_CMyStack)
{
_CMyStack();
}
else
{
qout << "Couldn't open the function CMyStack" << endl;
}
func2 _Push = (func2) m.resolve ("Push");
if(_Push)
{
_Push(4);
}
else
{
qout << "Couldn't open the function Push" << endl;
}
func3 _Pop = (func3) m.resolve ("Pop");
if(_Pop)
{
_Pop();
}
else
{
qout << "Couldn't open the function Pop" << endl;
}
func4 _isEmpty = (func4) m.resolve ("isEmpty");
if(_isEmpty)
{
_isEmpty();
}
else
{
qout << "Couldn't open the function isEmpty" << endl;
}
func5 _Print = (func5) m.resolve ("Print");
if(_Print)
{
_Print();
}
else
{
qout << "Couldn't open the function Print" << endl;
}
func6 _foo = (func6) m.resolve ("foo");
if(_foo)
{
_foo();
}
else
{
qout << "Couldn't open the function foo" << endl;
}
QTimer::singleShot(100, &app, SLOT(quit()));
system("pause");
return app.exec();
} |
|
m.h
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| #ifndef M_H
#define M_H
#include <iostream>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef M_API
# ifdef M_EXPORT
# define M_API __declspec(dllexport)
# else
# define M_API __declspec(dllimport)
# endif
#endif
M_API void foo();
class M_API CMyStack
{
public:
CMyStack();
void Push(int d);
int Pop();
bool isEmpty();
void Print();
private:
struct Node
{
int d;
Node *p;
};
Node *top;
};
#ifdef __cplusplus
}
#endif
#endif // M_H |
|
m.cpp
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| #include "m.h"
#include <stdio.h>
void foo()
{
std::cout << "hi" << std::endl;
}
CMyStack::CMyStack()
{
top = NULL;
}
void CMyStack::Push(int d)
{
Node *pv = new Node;
pv->d = d;
pv->p = top;
top = pv;
}
int CMyStack::Pop()
{
if (isEmpty())
{
return -1;
}
int temp = top->d;
Node *pv = top;
top = top->p;
delete pv;
return temp;
}
bool CMyStack::isEmpty()
{
return top ? false : true;
}
void CMyStack::Print()
{
while (top)
{
std::cout << Pop() << ' ';
}
std::cout << std::endl;
} |
|
Функцию foo видит нормально, но не видит функции в самом классе. В чём проблема?