-1

somefile.h の内容:

#ifndef __SOMEFILE_H
#define __SOMEFILE_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _table_t
{
     void (*somefunction1)();
     void (*somefunction2)(int a);
     void (*somefunction3)(int a, int *b);
}table_t;

void doSomething1();
void doSomething2();

#ifdef __cplusplus
} // error at this line: expected constructor, destructor, or type conversion before '(' token
#endif
#endif

上に示したのは、コード スニペットと、Linux でコードをコンパイルしたときに発生するエラーです。同じコードは、Windows でも問題なく正常にコンパイルされます。

ソースファイルについて:

all.h is a header file which includes:
#include "header1.h"
#include "header2.h"
#include "header3.h"
#include "somefile.h"

これがsomefile.cの内容です

#include "all.h" 
#include "header4.h"
jumptable_t jumptable_a = 
{
       a_function1();
       a_function2(int a);
       a_function3(int a, int *b);
}

//more code
void function1()
{
     a_function1();
}

void function2(int a)
{
    a_function2(a);
}

void function3(int a, int *b)
{
    a_function3(a, b);
}


void doSomething1()
{

}
void doSomething2()
{

}
4

2 に答える 2

2

先頭に 2 つのアンダースコアがあるマクロは不正です。インクルードガードを変更する必要があります。

于 2012-07-04T13:42:42.190 に答える
0

;の後にが必要}ですjumptable_a。の初期化子では、セミコロンの代わりにコンマを使用しますjumptable_a

中括弧は、somethink 関数のように見えますが、そうではありません。

また、somefile.h構造体では が呼び出されますtable_tが、somefile.cあなたは を使用していますjumptable_t。これは、ここに投稿を書いているときに導入されたエラーだと思います。

于 2016-05-25T13:06:12.433 に答える