Reputation: 1471
I made a simple tree class like this:
public ref class SimpleTreeNode {
public:
String^ Data;
List<SimpleTreeNode^>^ Children = gcnew List<SimpleTreeNode^>;
}
however, when i go and try to add stuff like this:
auto^ nstn = gcnew SimpleTreeNode();
nstn->Children->Add(gcnew SimpleTreeNode());
it says "Error: function "System::collections::generic::List::Add [with T=SimpleTreeNode^]" cannot be called with the given argument list
argument types are: (SimpleTreeNode^) object type is: System::Collections::Generic::List^"
what am I missing here? This should work, no?
Upvotes: 0
Views: 167
Reputation: 4798
For your case you should use keyword auto without the hat for both ref and value types. Like this:
auto nstn = gcnew SimpleTreeNode();
auto cN = nstn->Children->Count;
nstn->Children->Add(gcnew SimpleTreeNode());
auto cN2 = nstn->Children->Count;
Upvotes: 1