如何在dll中将struct包含在要导出的类中?

时间:2013-04-11 06:56:25

标签: c++ class dll struct

我正在尝试在cpp中编写一个后端,它可以读取测验问题的二进制文件,并且只在询问时显示答案。我想使用DLL链接,并遵循Microsoft的演练:http://msdn.microsoft.com/en-us/library/vstudio/ms235636.aspx,它不使用类成员。我也想导出它们,并且还包括类中的某些结构。

基本上,我希望能够声明和使用类的对象并使用其成员函数,只需将DLL包含在我承担的任何其他项目中。我该怎么做?在我的以下代码中,

#ifdef CXWDLL_EXPORTS
#define CXWAPI __declspec(dllexport) 
#else
#define CXWAPI __declspec(dllimport) 
#endif

#include<string>

using namespace std;

typedef unsigned long long UINT64
#define SIZE 15
#define GRIDSIZE 225
#define MAXCLUES 50

namespace cxw
{
    class CXWAPI CXWPuzzle
    {
        public:
            CXWPuzzle();
            virtual ~CXWPuzzle();
            struct Header
            {
                string signature;
                string version;
                short type;
            } header;
            struct Checksum
            {
                int header;
                int crossie;
                int grid;
                int clues;
                int solution;
                int file;
            } checksum;
            struct Contents
            {
                struct CHeader
                {
                    string title;
                    string author;
                    string copyright;
                    string notes;
                } cHeader;
                struct Grid
                {
                    short size;
                    UINT64 grid[4];
                    char filled[GRIDSIZE];
                    UINT64 filled[4];
                } grid;
                struct Clues
                {
                    string across[MAXCLUES];
                    string down[MAXCLUES];
                } clues;
                struct Solution
                {
                    char answers[GRIDSIZE];
                    string across[MAXCLUES];
                    string down[MAXCLUES];
                } solution;
            } contents;
    };
}

VS 2010编译器在<:p>处说“错误:预期声明”

} solution;

以及随后的结束括号。我还没有添加该类的方法。

我做错了什么?另外,我的代码会让我按照我的要求做我提到的吗?

1 个答案:

答案 0 :(得分:1)

struct Grid
{
    short size;
    UINT64 grid[4];
    char filled[225];
    UINT64 filled[4];
};

此处有一个错误,filled已声明两次。当我解决这个问题时,我无法重现你说的其他错误。