expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
ドラ
記事: 3
登録日時: 14年前

expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

#1

投稿記事 by ドラ » 14年前

はじめまして。私は今、コンパイルを行いたいと思い、挑戦しています。
しかし、うまく実行できません。

仕事で使用するあるソフトをコンパイルしようと思っています。
widowsにcygwinを入れて、その中で行っています。
コンパイラはg++です。
ファイルを何も変更せずにコンパイラをしたところ、多くのエラーが生じましたので、勉強しながら修正し、少しずつエラーを解決していきましたが、以下のエラーに非常に苦戦しております。
私が作成したものでないため、プログラム全文を載せることができないのですが、
必要部分とそれによるエラーメッセージをつけさせて頂きます。
どのように変更すれば実行されるのでしょうか?
まったくの初心者ですが、よろしくお願いします。

コード:


class Ring
{
 public:
	int valid;	// 0 = invalid; 1 = valid
	int type;	// 1 = normal; 2 = aromatic

	int num_member;
	{
		std::vector <int> atom_id;   // atom id in this ring
		std::vector <int> bond_id;   // bond id in this ring
	    return 0;
	}
		
	float centroid[3];

	Ring(); ~Ring();

	Ring(const Ring &original);
        Ring& operator = (const Ring &original);

	void Clear();
	void Show_Contents() const;
};


これを実行しますと、
error: expected unqualified-id before ‘{’ token
というエラーが生じます。
このエラーで指定された行は「int num_member;」の行です。
よろしくお願いします。

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

#2

投稿記事 by h2so5 » 14年前

コード:

    int num_member;
    {
        std::vector <int> atom_id;   // atom id in this ring
        std::vector <int> bond_id;   // bond id in this ring
        return 0;
    }
関数の定義をしているのに、引数リストが無くnum_memberの後に ; があるからです。
この部分を見る限りでは関数の定義をしたいわけでは無いようですので、

コード:

    int num_member;
    std::vector <int> atom_id;   // atom id in this ring
    std::vector <int> bond_id;   // bond id in this ring
ではないでしょうか?

ドラ
記事: 3
登録日時: 14年前

Re: expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

#3

投稿記事 by ドラ » 14年前

>h2so5さんへ

有難うございます。
教えて頂いたように訂正いたしますと、stdの2つの行に対して
error: ISO C++ forbids declaration of ‘vector’ with no type
error: invalid use of ‘::’
error: expected ‘;’ before ‘<’ token
error: ISO C++ forbids declaration of ‘vector’ with no type
error: invalid use of ‘::’
error: expected ‘;’ before ‘<’ token

というエラーが生じるようになりました。
どうしたら良いのでしょうか?

また、その後色々調べてみますと、
MakefileのdefaultのC++コンパイラはSGI MIPSのCCコンパイラだそうで、私が使っているのはGNUのg++コンパイラですので、MakefileスクリプトのCC=の部分を変更する必要があるかもしれません。
もしかしたらこれで解決できるのかもしれないですが、どのように変更したら良いのでしょうか?
defaultのMakefileの最初の方を載せさせて頂きます。

コード:


CC = g++                            # apply the GNU C++ compiler
#
OBJECT = main.o \
         basic.o \

よろしくお願いします。

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

#4

投稿記事 by h2so5 » 14年前

ドラ さんが書きました:error: ISO C++ forbids declaration of ‘vector’ with no type
error: invalid use of ‘::’
error: expected ‘;’ before ‘<’ token
error: ISO C++ forbids declaration of ‘vector’ with no type
error: invalid use of ‘::’
error: expected ‘;’ before ‘<’ token

というエラーが生じるようになりました。
どうしたら良いのでしょうか?
#include<vector>
がちゃんと記述されているか確認してください。

Makefileの件は私には詳しくは分かりません。

ドラ
記事: 3
登録日時: 14年前

Re: expected unqualified-id before ‘{’ tokenをどうしたら良いかわからない

#5

投稿記事 by ドラ » 14年前

>h2so5さんへ

確認しましたら、#include”vector.h"になっていました。
これを#include<vector>にするとエラーが消えました。
その他のエラーはなんとか自力で解決でき、かなり前進することができました。
有難うございます。

あと少しで完成しそうなのですが、今は
utilities.o:utilities.c:(.text+0x3cc): undefined reference to `__Unwind_SjLj_Resume'
utilities.o:utilities.c:(.text+0x3dc): undefined reference to `___gxx_personality_sj0'
utilities.o:utilities.c:(.text+0x401): undefined reference to `__Unwind_SjLj_Register'
utilities.o:utilities.c:(.text+0x480): undefined reference to `__Unwind_SjLj_Resume'
utilities.o:utilities.c:(.text+0x520): undefined reference to `__Unwind_SjLj_Resume'
utilities.o:utilities.c:(.text+0x66d): undefined reference to `__Unwind_SjLj_Unregister'
collect2: ld returned 1 exit status
make: *** [score] Error 1
というエラーに躓いています。

ちなみに

コード:

CC = g++                            # apply the GNU C++ compiler
#
OBJECT = utilities.o
#
LIB = -lm
#	 
score: $(OBJECT)
	$(CC) $(OBJECT) $(LIB) -o score 
#
utilities.o: utilities.c tool.h
#
を実行しています。

閉鎖

“C言語何でも質問掲示板” へ戻る