namespace/endl/ gcc 3.4 & 4.1.2.
Mark
area2051@gmx.de
Wed Apr 25 12:50:00 GMT 2007
Dear users,
a have posted my problem a view days ago, but i think it was not well
specified.
Let me describe my problem again.
I've got a project, which i should upgrade to a namespace functionality
and to compile it under the 4.x version.
I prepared every file with namespace namespacename { ...} and with it
the problem occurs, that the compiler warns the ostream endl method.
The endl method itself is overloaded with the option to write the output
to a file and/or to screen in the project.
the compile says following error message:
(compiler error 3.4)
g++-3.4 -I./Include -DABACUS_SYS_LINUX -DABACUS_COMPILER_GCC34 -Wall
-O3 -c sources/lp.cc -o tmp/linux20-gcc34/lp.o
sources/lp.cc: In function `std::ostream&
abacus::operator<<(std::ostream&, const abacus::ABA_LP&)':
sources/lp.cc:321: warning: the address of `abacus::ABA_OSTREAM&
abacus::endl(abacus::ABA_OSTREAM&)', will always evaluate as `true'
sources/lp.cc:323: warning: the address of `abacus::ABA_OSTREAM&
abacus::endl(abacus::ABA_OSTREAM&)', will always evaluate as `true'
sources/lp.cc:325: warning: the address of `abacus::ABA_OSTREAM&
abacus::endl(abacus::ABA_OSTREAM&)', will always evaluate as `true'
..............................................
(compiler error 4.1.2 )
g++-4.1 -I./Include -DABACUS_SYS_LINUX -DABACUS_COMPILER_GCC34 -Wall
-O3 -c sources/lp.cc -o tmp/linux20-gcc41/lp.o
./Include/abacus/array.h: In member function 'const
abacus::ABA_ARRAY<Type>& abacus::ABA_ARRAY<Type>::operator=(const
abacus::ABA_BUFFER<Type>&)':
./Include/abacus/array.h:401: error: no match for 'operator<<' in
'(((abacus::ABA_ARRAY<Type>*)this)->abacus::ABA_ARRAY<Type>::glob_->.abacus::ABA_GLOBAL::er
r() << "size of ABA_ARRAY too small.") << std::endl'
./Include/abacus/ostream.h:94: note: candidates are:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(char)
./Include/abacus/ostream.h:95: note:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(unsigned char)
./Include/abacus/ostream.h:96: note:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(signed char)
./Include/abacus/ostream.h:97: note:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(short int)
./Include/abacus/ostream.h:98: note:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(short unsigned int)
...................................................................
It looks like every call of endl in any overloading function will be
warned by compiler V3.4.
The hint to address endl explicit with std::endl is a nasty solution in
my eyes, but leads to success under V3.4.
Under the new compiler every endl-method at any place will be marked as
error (like above error message), even with std::endl!!
For the 4.1 Version i tried ABA_OSTREAM::endl but same error- message:
error: no match for 'operator<<' in (...) << abacus::ABA_OSTREAM::endl'
./Include/abacus/ostream.h:94: note: candidates are:
abacus::ABA_OSTREAM& abacus::ABA_OSTREAM::operator<<(char)
...
I really hope, that anyone can help me :-)
Thanks a lot.
Mark
In addition: Hear i post an excerpt of headerfile and sourcefile from my
ostream class and the corresponding array.h file.
headerfile:
......................
#ifndef ABA_OSTREAM_H
#define ABA_OSTREAM_H
#include <iostream>
#include <fstream>
using namespace std;
#include "abacus/abacusroot.h"
namespace abacus {
...
class ABA_OSTREAM;
typedef ABA_OSTREAM&(*ABA_OSTREAM_MANIP)(ABA_OSTREAM&);
class ABA_OSTREAM:public ostream,public ABA_ABACUSROOT{
public:
ABA_OSTREAM(ostream &out, const char *logStreamName = 0);
~ABA_OSTREAM();
ABA_OSTREAM&operator<<(char o);
ABA_OSTREAM&operator<<(const ABA_LPVARSTAT &o);
ABA_OSTREAM&operator<<(const ABA_CSENSE &o);
ABA_OSTREAM&operator<<(const ABA_LP &o);
//here comes more.............
ofstream* log() const;
friend ABA_OSTREAM& flush(ABA_OSTREAM &o);
friend ABA_OSTREAM& endl(ABA_OSTREAM &o);
private:
ostream &out_;
bool on_;
bool logOn_;
ofstream *log_;
};
} // End of Namespace
#endif // ABA_OSTREAM_H
sourcefile:
.................................
#include "abacus/ostream.h"
#include "abacus/string.h"
#include "abacus/history.h"
...
namespace abacus{
..
ABA_OSTREAM& flush(ABA_OSTREAM &o)
{
if (o.on_) o.out_ << flush;
if(o.logOn_) *(o.log_) << flush;
return o;
}
ABA_OSTREAM& endl(ABA_OSTREAM &o)
{
o << '\n';
if (o.on_) o.out_ << flush;
if(o.logOn_) *(o.log_) << flush;
return o;
}
} // End of Namespace
array.h
............
#ifndef ABA_ARRAY_H
#define ABA_ARRAY_H
#include <iostream>
using namespace std;
#include "abacus/global.h"
#include "abacus/buffer.h"
namespace abacus {
#ifdef ABACUS_NEW_TEMPLATE_SYNTAX
template<class Type>
class ABA_ARRAY;
template<class Type>
ostream& operator<< (ostream& out, const ABA_ARRAY<Type> &array);
#endif
template <class Type> class ABA_ARRAY : public ABA_ABACUSROOT {
public:
ABA_ARRAY(ABA_GLOBAL *glob, int size);
ABA_ARRAY(ABA_GLOBAL *glob, int size, Type init);
ABA_ARRAY(ABA_GLOBAL *glob, const ABA_BUFFER<Type> &buf);
ABA_ARRAY(const ABA_ARRAY<Type> &rhs);
~ABA_ARRAY();
const ABA_ARRAY<Type>& operator=(const ABA_ARRAY<Type>& rhs);
const ABA_ARRAY<Type>& operator=(const ABA_BUFFER<Type>& rhs);
friend ostream& operator<< (ostream& out, const ABA_ARRAY<Type>
&array);
Type& operator[](int i);
const Type& operator[](int i) const;
...
private:
ABA_GLOBAL *glob_;
int n_;
...
};
template <class Type>
inline ABA_ARRAY<Type>::ABA_ARRAY(ABA_GLOBAL *glob, int size)
:
glob_(glob),
n_(size)
{
#ifdef ABACUSSAFE
if (size < 0) {
glob_->err() << "ABA_ARRAY::ABA_ARRAY(): cannot construct array
with negative size" << endl;
exit(Fatal);
}
#endif
a_ = new Type[size];
}
..
template <class Type>
const ABA_ARRAY<Type>& ABA_ARRAY<Type>::operator=(const
ABA_ARRAY<Type>& rhs)
{
if (this == &rhs) return *this;
if (n_ != rhs.n_) {
glob_->err() << "ABA_ARRAY::operator= : dimensions of left and
right hand side ";
glob_->err() << "are different (" << n_ << " != " << rhs.n_ << ")"
<< endl;
exit(Fatal);
}
glob_ = rhs.glob_;
n_ = rhs.n_;
for (int i = 0; i < n_; i++) a_[i] = rhs[i];
return *this;
}
template <class Type>
const ABA_ARRAY<Type>& ABA_ARRAY<Type>::operator=(const
ABA_BUFFER<Type>& rhs)
{
if (n_ < rhs.size()) {
glob_->err() << "ABA_ARRAY::operator=(const
ABA_BUFFER&):"<<endl; //OR ????-> ABA_OSTREAM::endl;
glob_->err() << "size of ABA_ARRAY too small."<<endl;
exit(Fatal);
}
const int rhsNumber = rhs.number();
for (int i = 0; i < rhsNumber; i++) a_[i] = rhs[i];
return *this;
}
template <class Type>
ostream& operator<<(ostream &out, const ABA_ARRAY<Type> &array)
{
const int s = array.size();
for (int i = 0; i < s; i++) out << i << ": " << array[i] << endl;
return out;
}
} // End of Namespace
#endif // !ABA_ARRAY_H
More information about the Gcc-help
mailing list