What's wrong witht this code?

class RadianLongitudeLatitude : public std::pair<double,double>
{
public:
RadianLongitudeLatitude (const LongitudeLatitude & longla)
: std::pair<double,double>::first (longla.first*constant::pi/180), std::pair<double,double>::second (longla.second*constant::pi/180)
{};
};

I got error:
Error 1 error C2039: 'first' : is not a member of 'std::pair<_Ty1,_Ty2>' z:\business\fromwork\currentprojects\program\library\cpp\locationbasedads\locations.h 22 locationBasedAds


Of course first is a member of std::pair.

...but you can't initialize it like that.

Try this instead:

1
2
3
4
5
6
7
class RadianLongitudeLatitude : public std::pair<double,double>
{
public:
  RadianLongitudeLatitude (const LongitudeLatitude & longla)
    : std::pair<double,double> (longla.first*constant::pi/180), longla.second*constant::pi/180)
    { }
};

You have to use the same technique in your LongitudeLatitude class, no?

Hope this helps.
What's the difference between my code and yours?
1
2
3
4
5
6
7
class RadianLongitudeLatitude : public std::pair<double,double>
{
public:
RadianLongitudeLatitude (const LongitudeLatitude & longla)
: std::pair<double,double>::first (longla.first*constant::pi/180), std::pair<double,double>::second (longla.second*constant::pi/180)
{};
};
Oh I see, you're calling constructor of std::pair<double,double>

that would work.

But still first is a member of RadianLongitudeLatitude class. So why the error?
it's a member of RadianLongitudeLatitude, not of std::pair and you call std::pair<double,double>::first in the constructor
RadianLongitudeLatitude is a decendant of std::pair<double,double>::first

I think I tried first (longla.first*constant::pi/180) and got the same error.
Topic archived. No new replies allowed.