string has not be decleared?

K

key9

Hi all
when I using g++ -c to compile my code:

//root_element.hpp
#ifndef __ROOTELEMENT
#define __ROOTELEMENT

#include <string>

class RootElement{

public:

virtual
RootElement& operator<< (RootElement& Re, string& str);

};

#endif /* __ROOTELEMENT */


//root_element.cpp

//#include <string>
#include "root_element.hpp"
#include <sstream>

RootElement::
RootElement&
operator<< (RootElement& Re, string& str)
{


std::stringstream Temp;
Temp << str;
// acceptiStr(Temp.str ()); don't care this , just a NOP
return Re;

}

linux:~/rman_design/classes/test$ g++ -c root_element.cpp
root_element.hpp:14: error: a€?stringa€? has not been declared
root_element.hpp:14: error: a€?RootElement&
RootElement::eek:perator<<(RootElement&, int&)a€? must take exactly one
argument
root_element.cpp:9: error: a€?stringa€? has not been declared


2 questions:
1. why it told me string not been declared?
2. RootElement::eek:perator<<(RootElement&, int&) , here int& ,does g++ deal
undefined type as int?

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with:
.../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre
--enable-mpfr --disable-werror --with-tune=pentium4 --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
 
R

red floyd

key9 said:
Hi all
when I using g++ -c to compile my code:

//root_element.hpp
#ifndef __ROOTELEMENT
#define __ROOTELEMENT

1. This is illegal. Any identifier with two consecutive underscores is
reserved to the implementation. Don't just get rid of one of them, an
identifier with a leading underscore followed by an uppercase letter is
also reserved.
#include <string>

class RootElement{

public:

virtual
RootElement& operator<< (RootElement& Re, string& str);
RootElement& operator<<(RootElement& Re, std::string& str);
2 questions:
1. why it told me string not been declared?
string is in the std::namespace.
2. RootElement::eek:perator<<(RootElement&, int&) , here int& ,does g++ deal
undefined type as int?
Cascade error. The compiler is now confused.
 
A

Alf P. Steinbach

* key9:
Hi all
when I using g++ -c to compile my code:

//root_element.hpp
#ifndef __ROOTELEMENT

Identifiers with two successive underscores are reserved to the
implementation.

Don't use them.

#define __ROOTELEMENT

#include <string>

class RootElement{

public:

virtual
RootElement& operator<< (RootElement& Re, string& str);

Presumably you mean this operator to be called like

rootElement << "bananas"

Note that only two arguments are specified in this call.

Yet your declaration has three: this, Re and str.

};

#endif /* __ROOTELEMENT */


//root_element.cpp

//#include <string>
#include "root_element.hpp"
#include <sstream>

RootElement::
RootElement&
operator<< (RootElement& Re, string& str)

That should be

RootElement& RootElement::eek:perator<<


[snip]
2 questions:
1. why it told me string not been declared?
2. RootElement::eek:perator<<(RootElement&, int&) , here int& ,does g++ deal
undefined type as int?

Don't know, but I hope the above helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top