开发者

ostream problems c++

im not sure why i am having problems with ostream. If i use using namespace std; it throws up a bunch more errors like linker errors.

This is my code where i am having problems and the errors.

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'

this is the container .h header file where i am having problems with

#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

if i use

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

it fixes the errors however, in the proceeding .cpp file i get the same errors above in the put function. i did try the std:: in the put functions but it threw up a ton of linker errors. i tried to use namespace std; also but that throws up a ton of linker errors.

#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;

}

heres the errors i now 开发者_StackOverflowget in that container.cpp file

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

i tried to #include fstream

I will appreciate any help here. theres a ton more code but i dont think you need to see the other files.


Maybe you forget the std namespace. ostream is declared in std namespace, so you need to add "using namepsace std" before the declaration of Container or use scope resolution (std::ostream).


void Container::Put(ostream&)const

{ 
    return;

}

I'm still a little new at this, but don't you need a variable name here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜