function definition inside a class

Hello.I saw this wierd definition for a class and it works.how is it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class gps_position
{
    friend std::ostream & operator<<(std::ostream &os, const gps_position &gp);
    friend class boost::serialization::access;
    int degrees;
    int minutes;
    float seconds;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int /* file_version */){
        ar & degrees & minutes & seconds;
    }
public:
    // every serializable class needs a constructor
    gps_position(){};
    gps_position(int _d, int _m, float _s) : 
        degrees(_d), minutes(_m), seconds(_s)
    {}
};
Last edited on
It would help if you explained what about it seems "weird" to you or why you think this shouldn't work.
The following function definition is wierd:

/***********************************************************
* void serialize(Archive & ar, const unsigned int /* file_version */){ *
* ar & degrees & minutes & seconds; *
* } *
***********************************************************/

It's wierd because the second parameter has no name
That's valid in c/c++. Also called dummy arguments. It means the function is not actually using the passed argument. But it is required when calling.
Parameters don't have to have a name if they are not used. In the example you provide I could speculate that it might be because a future version of the program may add additional functionality or the function may simply be remaining compatible with previous versions of the program that did need the parameter name. I could also guess that the name has been commented out to stop the compiler issuing a warning about an unused parameter.
Topic archived. No new replies allowed.