1
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <regex>

using namespace std;

class Parser {
protected:
    // regex: containers
    static const regex rxProc("procedure\s+([\w]+)\s*{");
}

パーツのエラーが発生しています"procedure\s+([\w]+)\s*{"。型指定子が必要です。私は何か間違ったことをしているに違いない?

4

2 に答える 2

2

ここで他の回答を見て、実際にコンパイラに何を求めているのかを理解してください。クラス内で定数を作成しようとしている場合は、ここで解決策を提供します。

C++ で静的メンバーを使用するのは楽しいですが、POD (plain-old-data) メンバーに対してのみです。より複雑なメンバーの場合、事態は悪化します。これでもchar*スケールアップしません。古き良き C を使用する#defineことは、時には良い考えです。C++ であってもです。

このようなものは、コンパイルの問題を修正します。で遊んで#if 0古いコードをトリガーし、を使用してコンパイルしますg++ -std=gnu++0x -c test1.cpp

#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <regex>

using namespace std;

#if 0
// my fix

// in your H file
class Parser {
protected:
    // regex: containers
    static const regex rxProc;
};    
// in your CPP file
const regex Parser::rxProc = regex("procedure\\s+([\\w]+)\\s*{");
#else

// your old code
class Parser {
protected:
    // regex: containers
    static const regex rxProc("procedure\\s+([\\w]+)\\s*{");
};
#endif

(構文ツリーを定義するために正規表現を使用するという問題にさえ入っていません...またはPascalファイルを解析しています...これはただの悪い考えであり、ああ、何度も壊れます...ただしないでください)

于 2012-10-29T07:15:15.633 に答える
1

コンパイラは、型の 1 つのパラメーターをrxProc返しconst regexたり受け取ったりする静的関数を宣言していると見なし、型を取得できません。

于 2012-10-29T07:08:55.700 に答える