{"id":513,"date":"2011-01-06T19:50:40","date_gmt":"2011-01-06T19:50:40","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=513"},"modified":"2022-02-17T06:24:04","modified_gmt":"2022-02-17T06:24:04","slug":"creating-structures-class-of-our-own-data-types","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/classes-objects-struct\/creating-structures-class-of-our-own-data-types","title":{"rendered":"Structures\/Class Of Our Own Data Types"},"content":{"rendered":"<p>Often with a class you want the application to use structures or variables that can be passed to the classes functions to be read or written with data.  There is no real difference between a class or structure in c++.NET so create the structure as a class.<\/p>\n<h5>In the header file of a class create this before the the main class&#8217;s ref class MyClassName (must be before so you can reference the class names in the main class)<\/h5>\n<pre><code>\r\n\t\/\/------------------------------------------\r\n\t\/\/----- CLASSES FOR CONFIGURATION DATA -----\r\n\t\/\/------------------------------------------\r\n\tpublic ref class MyStructureClassName\r\n\t{\r\n\tpublic:\r\n\t\tproperty int Connection;\t\t\/\/Define the variables types here\r\n\t\tproperty String ^Name;\r\n\t\tproperty array ^Type;\r\n\t\tproperty array ^IpAddress;\r\n\r\n\t\tMyStructureClassName::MyStructureClassName(void)\r\n\t\t{\r\n\t\t\t\/\/Strings and arrays will be nullptr until created\r\n\t\t\tName = \"\";\r\n\t\t\tType = gcnew array(NUM_OF_CONTROLLERS);\t\/\/Create them in a constructor\r\n\t\t\tIpAddress = gcnew array(NUM_OF_CONTROLLERS);\r\n\t\t}\r\n\r\n\t};\r\n\r\n\t\/\/Now your main class...\r\n\t\/\/-------------------------------\r\n\t\/\/----- CONFIGURATION CLASS -----\r\n\t\/\/-------------------------------\r\n\tref class Configuration\r\n\t{\r\n\tThe main class\r\n<\/code><\/pre>\n<h5>In your main application<\/h5>\n<pre><code>\r\n\/\/IN YOUR DECLARATIONS:\r\n\/\/\tprivate: MyClassNamespace::MyStructureClassName ^MyStructure1;\r\n\/\/IN YOUR CONSTRUCTOR\r\n\/\/\tMyStructure1= gcnew MyClassNamespace::MyStructureClassName();\r\n\/\/START USING\r\n\/\/\tMyStructure1-&gt;# = #;\r\n<\/code><\/pre>\n<h4>Serializing A Class<\/h4>\n<p>See in serialization section <a href=\"https:\/\/ibex.tech\/visualcpp\/programming\/visual-cpp-cli-dot-net\/serialization\/serialization-of-a-class\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often with a class you want the application to use structures or variables that can be passed to the classes functions to be read or written with data. There is no real difference between a class or structure in c++.NET so create the structure as a class. In the header file of a class create [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-513","post","type-post","status-publish","format-standard","hentry","category-classes-objects-struct"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=513"}],"version-history":[{"count":7,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":1066,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/513\/revisions\/1066"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}