 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
key9 Guest
|
Posted: Sat Nov 25, 2006 10:10 am Post subject: string has not be decleared? |
|
|
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::operator<<(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::operator<<(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) |
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Sat Nov 25, 2006 10:11 am Post subject: Re: string has not be decleared? |
|
|
key9 wrote:
| Quote: | 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.
| Quote: |
#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::operator<<(RootElement&, int&) , here int& ,does g++ deal
undefined type as int?
Cascade error. The compiler is now confused.
|
|
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Sat Nov 25, 2006 10:11 am Post subject: Re: string has not be decleared? |
|
|
* key9:
| Quote: | 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.
| Quote: | #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.
| Quote: | };
#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::operator<<
[snip]
| Quote: | 2 questions:
1. why it told me string not been declared?
2. RootElement::operator<<(RootElement&, int&) , here int& ,does g++ deal
undefined type as int?
|
Don't know, but I hope the above helps.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|