1

Following up from my previous question.

Can anyone explain why the following code compiles without any errors:

typedef array<VdbMethodInfo^> MethodArray;
typedef array<VdbParameterInfo^> ParameterArray;
ParameterArray^ parameters = gcnew ParameterArray {
    gcnew VdbParameterInfo("name", "string", "Paul")};
MethodArray^ methods = gcnew MethodArray {
    gcnew VdbMethodInfo("createTable", parameters)
};

Yet this gives me "error C2440: 'initializing' : cannot convert from 'VdbParameterInfo ^' to 'VdbMethodInfo ^"

typedef array<VdbMethodInfo^> MethodArray;
typedef array<VdbParameterInfo^> ParameterArray;
MethodArray^ methods = gcnew MethodArray {
    gcnew VdbMethodInfo("createTable", gcnew ParameterArray {
        gcnew VdbParameterInfo("name", "string", "Paul")};
    )
};

All I've done is attempt to "nest" the parameter array inside the method array initialization... Not directly mind - VdbMethodInfo's constructor takes, as a second argument, a ParameterArray.

It seems to imply that managed C++ array initialization expects any recursive nesting to have the same type... (i.e. I think this must be a bug)

Related question : here

1 Answer 1

2

I've found a workaround which makes the syntax cleaner anyway. I use the "..." syntax (Managed C++ equivalent to the C# "params" keyword"):

public ref class MetaData
{
    typedef array<VdbMethodInfo^> MethodArray;
    typedef array<VdbParameterInfo^> ParameterArray;
    static ParameterArray^ params(... ParameterArray^ p)
    {
        return p;
    }
public:
    static array<VdbMethodInfo^>^ Instance()
    {
        ParameterArray^ parameters = gcnew ParameterArray { gcnew VdbParameterInfo("name", "string", "Paul")};
        MethodArray^ methods = gcnew MethodArray {
            gcnew VdbMethodInfo("createTable",
                params(gcnew VdbParameterInfo("name", "string", "Paul"),
                       gcnew VdbParameterInfo("age", "number", "25")))
        };

        return methods;
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.