Doubt about functions and classes

Asked

Viewed 53 times

0

class base_token
{

    public:

        typedef enum {  t_invalid_token=0, t_symbol, t_integer, t_literal,

                        t_punctuation, t_keyword

                     } type_of_token;

    private:

        type_of_token token_type;

    public:

        base_token(type_of_token token) : token_type(token) { };

        type_of_token get_type() { return token_type; };

        virtual const char *  parse_token(const char * s) = 0;

};

That line is saying what (syntax)?

base_token(type_of_token token) : token_type(token) { };

1 answer

0


I’ll give you an answer thinking semantically, I believe this is the purpose of your question. If it’s not, I’ll edit it and parse it.

This line declares a constructor for the class base_token. Constructors are methods that have the same class name, do not return any type (not even void).

This constructor requires a single parameter of type type_of_token. The name of the parameter is token.

Constructor initializes the field token_type (declared with access private) with the value passed in the argument token.

The body of the method is empty.

This manufacturer (under these specific conditions) is equivalent to:

base_token(type_of_token token) {
    token_type = token;
}

Both, in the context of the displayed class, have the same effect.

It is worth noting that this is a question of C++, not C.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.