By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

error compiling this

P: n/a

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,Tt4p;
std::vector<Pvp;
};

class RT {
std::vector<doublevi;
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,Tf(*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>::operator()(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, boolstd::_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::other>::iterator, boolstd::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
Nov 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* 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.

--
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?
Nov 21 '06 #2

P: n/a
"Alf P. Steinbach" <al***@start.nowrites:
* 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.
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>::operator()(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, boolstd::_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::other>::iterator, boolstd::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<doublevi;
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,Tt4p;
std::vector<Pvp;
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,Tf(*b, tmp);
info.t4p.insert(f);
}
}
};
int main(){
Info i;
Spac_task st;
}

Nov 21 '06 #3

P: n/a
Gary Wessle wrote:
"Alf P. Steinbach" <al***@start.nowrites:
* 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.

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>::operator()(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, boolstd::_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::other>::iterator, boolstd::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

Nov 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.