Sign in to follow this  

[.net] How to make an Object class in Visual C++

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am using Visual C++ Express Edition 2005. I want to ask about how to make an Object class? My application data consists of these: 1. Company Name 2. Employee Name 3. Age 4. Gender 5. Address 6. City 7. ZIP 8. Phone What inside my mind is like this: Class company { public: String ^compname; public: String ^empname; public: String ^age; public: String ^gender; public: String ^address; public: String ^city; public: String ^zip; public: String ^phone; }; but they always error and I just confused what to do. I want to make them as an object so that I can manage them later to deal with Tag. But I don't understand how to make the Object class. Like in the example below, I want to make it like this but I don't know how to make the Customer object (the object in the example below) and manage them for data entry and data loading. Please show me the code example of making the Object and the usage for loading and accepting data because I want to fill the treeView with these data and also it is works for data filtering. Thank you very much. void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode^ rootNode = gcnew TreeNode; rootNode->Text = "CustomerList"; // Add a main root treenode. myTreeView->Nodes->Add( rootNode ); // Add a root treenode for each 'Customer' object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current); // Add a child treenode for each Order object. int i = 0; array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(5); IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ myOrder = safe_cast<Order^>(myEnum->Current); myTreeNodeArray[ i ] = gcnew TreeNode( myOrder->OrderID ); i++; } TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,myTreeNodeArray ); // Display the customer names with and Orange font. customerNode->ForeColor = Color:range; // Store the Customer Object* in the Tag property of the TreeNode. customerNode->Tag = myCustomer; myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode ); } }

Share this post


Link to post
Share on other sites
Regarding your class definition: using google will present you with TONS of examples of how to define classes in c++/clr. It almost looks like you're trying to define the class the way you would in c#.

I'm not 100% sure what you're asking in the second question, but it looks like basic object orientated programming principles, for which there's also a ton of resources.

My advice: unless you need to mix managed and native code, use c# instead of c++/clr. Purely managed c++/clr really can't do anything that c# can't, and is way more work. In my opinion using c++/clr for purely managed code is just being masochistic. Especially when you're learning.

Share this post


Link to post
Share on other sites

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this