Are there any restrictions on the types of typecast statements?

I was wondering if anyone knows what restrictions are on the / typecast conversion operator?

So, for example, I can have the following override operators:

class Test {
    operator int() { return 0; };
    operator int*() { return nullptr; };
}

For a regular function, I could also have a pointer to an array type. For instance.

int (*MyFunc())[4] { return nullptr; };

However, I do not know how to do the same for the conversion operator (or even if it is legal). I tried several different options and VS2010 and no one works. (For instance:

operator int (*())[4] { return nullptr; };
operator int(*)[4]() { return nullptr; };

, VS2010 , . . - ? , - " ", . , , ++.

+5
2

, . , , . ( kin) :

ยง12.3.2
conversion-function-id:
    operator conversion-type-id
conversion-type-id:
    type-specifier-seq conversion-declarator[opt]
conversion-declarator:
    ptr-operator conversion-declarator[opt]

ยง7.1.6
type-specifier:
    trailing-type-specifier
    class-specifier
    enum-specifier
trailing-type-specifier:
    simple-type-specifier
    elaborated-type-specifier
    typename-specifier
    cv-qualifier
type-specifier-seq:
    type-specifier attribute-specifier-seq[opt]
    type-specifier type-specifier-seq
trailing-type-specifier-seq:
    trailing-type-specifier attribute-specifier-seq[opt]
    trailing-type-specifier trailing-type-specifier-seq

, , . ( .) , typedef-name ( typename-specifier), typedef , :

struct Test {
    typedef int operator_type[4];

    operator operator_type*() { return nullptr; };
};

, typedef, , .

+3

typedef , ,

operator Type () {}

typedef

typedef int (*foo())[4];
typedef int(*bar)[4];

typedef

operator foo() { return nullptr; }// nullptr ", 4 int, .

operator bar() { return nullptr; }// , nullptr 4 int s

+6

All Articles