error compiling this

G

Gary Wessle

Hi
I tried so long, so many ways to find out why this code is not
compiling, I appreciate any help with it,

thank you

****************************************************************
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <utility> // std::pair
#include <map>

using namespace std;

class T {
double _bef, _aft;
public:
T(double b, double a):
_bef(b),
_aft(a)
{}
double bef() const {return _bef;}
double aft() const {return _aft;}
};

class P{
protected:
char _fir[40];
char _sec[40];
char _all[80];
public:
P( const char* all)
{
strncpy(_fir, all, 3);
_fir[3]='\0';
strncpy(_sec, all+4, 3);
_sec[3]='\0';
strncpy(_all, all, 3);
_all[3]='\0';
strcat(_all, _sec);
}
char* fir() { return _fir;}
char* sec() { return _sec;}
char* all() { return _all;}
};

class Info{
int x;
public:
Info()/* bunch of stuff here */ {}
std::map<P,T> t4p;
std::vector<P> vp;
};

class RT {
std::vector<double> vi;
double a, b;
public:
RT();
T getRt(const P& p){
T k(a,b);
return k;
}
};


class Spac_task{

public:
Info info;
void c_d(){
for ( vector<P>::iterator b=info.vp.begin(); b!=info.vp.end(); ++b){
T tmp = info.RT.getrt( *b );
pair<P,T> f(*b, tmp);
info.t4p.insert(f); //<<<<<<<<<<<<<<<< error line
}
}
};


int main(){
Info i;
Spac_task st;
}

****************************************************************
cd /home/fred/myProg/toy/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
main.cpp: In member function ‘void Spac_task::c_d()’:
main.cpp:69: error: ‘class Info’ has no member named ‘RT’
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h: In member function ‘bool std::less<_Tp>::eek:perator()(const _Tp&, const _Tp&) const [with _Tp = P]’:
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:921: instantiated from ‘std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = P, _Val = std::pair<const P, T>, _KeyOfValue = std::_Select1st<std::pair<const P, T> >, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]’
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:396: instantiated from ‘std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::eek:ther>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair<const _Key, _Tp>&) [with _Key = P, _Tp = T, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]’
main.cpp:71: instantiated from here
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h:227: error: no match for ‘operator<’ in ‘__x < __y’
make: *** [main.o] Error 1
make: Target `proj' not remade because of errors.

Compilation exited abnormally with code 2 at Tue Nov 21 15:18:04
 
A

Alf P. Steinbach

* Gary Wessle:
Hi
I tried so long, so many ways to find out why this code is not
compiling, I appreciate any help with it,

You're using the name RT as if it were a member of some class of which
it's not a member.
 
G

Gary Wessle

* Gary Wessle:

You're using the name RT as if it were a member of some class of which
it's not a member.

oops,

I fixed that but it is complaining, the error seams to me like it
needs some operator== overloading, I am just guessing.

thanks

****************************************************************
cd /home/fred/myProg/toy/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h: In member function ‘bool std::less<_Tp>::eek:perator()(const _Tp&, const _Tp&) const [with _Tp = P]’:
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:921: instantiated from ‘std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = P, _Val = std::pair<const P, T>, _KeyOfValue = std::_Select1st<std::pair<const P, T> >, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]’
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:396: instantiated from ‘std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::eek:ther>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair<const _Key, _Tp>&) [with _Key = P, _Tp = T, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]’
main.cpp:73: instantiated from here
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h:227: error: no match for ‘operator<’ in ‘__x < __y’
make: *** [main.o] Error 1
make: Target `proj' not remade because of errors.

Compilation exited abnormally with code 2 at Tue Nov 21 17:00:31


****************************************************************
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <utility> // std::pair
#include <map>

using namespace std;

class T {
double _bef, _aft;
public:
T(double b, double a):
_bef(b),
_aft(a)
{}
double bef() const {return _bef;}
double aft() const {return _aft;}
};

class P{
protected:
char _fir[40];
char _sec[40];
char _all[80];
public:
P( const char* all)
{
strncpy(_fir, all, 3);
_fir[3]='\0';
strncpy(_sec, all+4, 3);
_sec[3]='\0';
strncpy(_all, all, 3);
_all[3]='\0';
strcat(_all, _sec);
}
char* fir() { return _fir;}
char* sec() { return _sec;}
char* all() { return _all;}
};


class RT {
std::vector<double> vi;
double a, b;
public:
RT();
T getrt(const P& p){
T k(a,b);
return k;
}
};

class Info{
int x;
public:
Info()/* bunch of stuff here */ {}
std::map<P,T> t4p;
std::vector<P> vp;
RT rt;
};


class Spac_task{

public:
Info info;
void c_d(){
for ( vector<P>::iterator b=info.vp.begin(); b!=info.vp.end(); ++b){
T tmp = info.rt.getrt( *b );
pair<P,T> f(*b, tmp);
info.t4p.insert(f);
}
}
};


int main(){
Info i;
Spac_task st;
}
 
D

doina

Gary said:
* Gary Wessle:

You're using the name RT as if it were a member of some class of which
it's not a member.

oops,

I fixed that but it is complaining, the error seams to me like it
needs some operator== overloading, I am just guessing.

thanks

****************************************************************
cd /home/fred/myProg/toy/
make -k
g++ -gdwarf-2 -c -o main.o main.cpp
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h: In member function 'bool std::less<_Tp>::eek:perator()(const _Tp&, const _Tp&) const [with _Tp = P]':
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:921: instantiated from 'std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = P, _Val = std::pair<const P, T>, _KeyOfValue = std::_Select1st<std::pair<const P, T> >, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:396: instantiated from 'std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename _Alloc::rebind<std::pair<const _Key, _Tp> >::eek:ther>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair<const _Key, _Tp>&) [with _Key = P, _Tp = T, _Compare = std::less<P>, _Alloc = std::allocator<std::pair<const P, T> >]'
main.cpp:73: instantiated from here
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y'
make: *** [main.o] Error 1
make: Target `proj' not remade because of errors.

You have to provide the operator< for P because P is the key of the
map, so comparisons are necessary. Probably the default operator should
be also overloaded, as I see from your errors. I didn't have time to
think about this, so I'm not too sure...

Good luck

Regards,
Doina Babu
 

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

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top