1

ostream で問題が発生する理由がわかりません。名前空間 std; を使用する場合。リンカーエラーなどのエラーがさらに多く発生します。

これは、問題とエラーが発生している私のコードです。

virtual void Put (ostream&) const;

error C2061: syntax error : identifier 'ostream'
error C2065: 'ostream' : undeclared identifier
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)
error C2061: syntax error : identifier 'ostream'
error C2061: syntax error : identifier 'ostream'

これは、私が問題を抱えているコンテナ.hヘッダーファイルです

#ifndef CONTAINER_H
#define CONTAINER_H
#include <ostream>
#include <iostream>
#include "Object.h"
#include "NullObject.h"
#include "Ownership.h"
#include "Iterator.h"
#include "Visitor.h"


class Container : public virtual Object,  public virtual Ownership
{
protected:
unsigned int count;

Container ();
public:
virtual unsigned int Count () const;
virtual bool IsEmpty () const;
virtual bool IsFull () const;
//  virtual HashValue Hash () const;
virtual void Put (ostream&) const;
virtual Iterator& NewIterator () const;

virtual void Purge () = 0;
virtual void Accept (Visitor&) const = 0;
};

#endif

私が使用する場合

virtual void Put (std::ostream&) const;

エラーは修正されますが、進行中の.cppファイルでは、put関数で上記と同じエラーが発生します。put 関数で std:: を試してみましたが、大量のリンカー エラーが発生しました。名前空間 std を使用しようとしました。また、大量のリンカ エラーが発生します。

#include "Container.h"
#include "NullIterator.h"
#include <ostream>
#include <iostream>


Container::Container () :
count (0)
{}

unsigned int Container::Count () const
{ return count; }

bool Container::IsEmpty () const
{ return Count () == 0; }

bool Container::IsFull () const
{ return false; }

Iterator& Container::NewIterator () const
{ return *new NullIterator (); }

void Container::Put(ostream&)const

{ 
    return;

}

そのcontainer.cppファイルに表示されるエラーは次のとおりです

error C2065: 'ostream' : undeclared identifier
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)

#include fstream を試してみました

ここで何か助けていただければ幸いです。さらに多くのコードがありますが、他のファイルを見る必要はないと思います。

4

2 に答える 2

1

たぶんあなたはstd名前空間を忘れています。ostreamはstd名前空間で宣言されているため、Containerの宣言の前に「usingnamepsace std」を追加するか、スコープ解決(std :: ostream)を使用する必要があります。

于 2010-11-01T02:13:56.060 に答える
0
void Container::Put(ostream&)const

{ 
    return;

}

私はまだこれに少し慣れていませんが、ここに変数名は必要ありませんか?

于 2012-06-14T09:22:38.857 に答える