So I'm very new to C++. rusty with dev, and need some help.
I am using the treeView class, which contains contains an extension: treeNode class. I would like to add a variable to the treeNode class to include a string variable named strData. So that when a Node in a tree is selected I can say treeView1->SelectedNode::strData and it'll pull the string.
This is what I think it would look like:
#include <string>
class treeNode{
public:
string strData;
};
I realize that I should probably make strData private, and have a get/set function, but i'd like to keep it simple for now.
Follow up question: (once this is working, would this be the correct way to get the string? treeView1->SelectedNode::strData)
Well I think you've already read the C++ tutorial on classes, and your class looks fine.
You're using the wrong operator. :: is the scope resolution operator, and doesn't apply to members of a class. You should be using the . operator to access members. (-> is a shortcut operator used when dereferencing pointers). Maybe you should brush up on the differences between references, pointers, values, etc.
So I think I explained my question wrong, I want to add something to an existing class:
System::Windows::Forms::TreeNode
When I compiled the code with the above mentioned class definition and tried to set the string variable with:
treeView1->SelectedNode->strData = "abba";
I got this error:
Error 2 error C2039: 'strData' : is not a member of 'System::Windows::Forms::TreeNode' c:\users\lapidusva25\documents\visual studio 2010\projects\jobapply\jobapply\Form1.h 253 1 JobApply
Error 1 error C3625: 'MegaNode': an unmanaged type cannot derive from a managed type 'System::Windows::Forms::TreeNode' C:\Users\lapidusva25\documents\visual studio 2010\Projects\JobApply\JobApply\JobApply.cpp 7 1 JobApply
Error 2 error C2499: 'TreeNode' : a class cannot be its own base class C:\Users\lapidusva25\documents\visual studio 2010\Projects\JobApply\JobApply\JobApply.cpp 7 1 JobApply
This when I tried treeNode:
Error 1 error C3625: 'treeNode': an unmanaged type cannot derive from a managed type 'System::Windows::Forms::TreeNode' C:\Users\lapidusva25\documents\visual studio 2010\Projects\JobApply\JobApply\JobApply.cpp 7 1 JobApply