{"id":75,"date":"2010-03-17T12:22:00","date_gmt":"2010-03-17T12:22:00","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=75"},"modified":"2022-02-17T06:24:06","modified_gmt":"2022-02-17T06:24:06","slug":"create-a-new-class","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/classes-objects-struct\/create-a-new-class","title":{"rendered":"Create A New Class"},"content":{"rendered":"<p>To create A new class, which will create the .cpp and .h files:<br \/>\nProject &gt; Add Class &gt; C++ Class<br \/>\nTypically:<\/p>\n<p style=\"padding-left: 30px;\">Specify the class name.\u00a0 You don&#8217;t need to provide a base class.<\/p>\n<p style=\"padding-left: 30px;\">Select public and select managed.<\/p>\n<h5>In the new .h file add the following:<\/h5>\n<p>The namespace can be a distinct name, or for classes that are part of a main ap you can just use the ap&#8217;s namespace name:<\/p>\n<pre><code>\r\n#pragma once\r\n\r\n\/\/----- NOTES -----\r\n\/\/\r\n\/\/USING THIS CLASS IN A PROJECT:-\r\n\/*\r\n\/\/TOP OF YOUR FILE\r\n#include \"MyClass.h\"\r\n\/\/USING NAMESPACES\r\n\tusing namespace OurLibraries;\r\n\/\/IN YOUR DECLARATIONS:\r\n\tprivate: MyClass ^MyClass1;\r\n\/\/IN YOUR CONSTRUCTOR\r\n\tMyClass1 = gcnew MyClass();\r\n\/\/START USING\r\n\tMyClass1-&gt;#();\r\n*\/\r\n\r\nnamespace OurLibraries\r\n{\r\n\r\n\tusing namespace System;\r\n\tusing namespace System::ComponentModel;\r\n\tusing namespace System::Collections;\r\n\r\n\tpublic ref class MyClass\r\n\t{\r\n\tprivate:\r\n\t\t\/\/---------------------------\r\n\t\t\/\/----- PRIVATE DEFINES -----\r\n\t\t\/\/---------------------------\r\n\r\n\tprivate:\r\n\t\t\/\/-----------------------------\r\n\t\t\/\/----- PRIVATE FUNCTIONS -----\r\n\t\t\/\/-----------------------------\r\n\r\n\tpublic:\r\n\t\t\/\/----------------------------\r\n\t\t\/\/----- PUBLIC FUNCTIONS -----\r\n\t\t\/\/----------------------------\r\n\t\tMyClass(void);\r\n\r\n\tprivate:\r\n\t\t\/\/-----------------------------\r\n\t\t\/\/----- PRIVATE VARIABLES -----\r\n\t\t\/\/-----------------------------\r\n\r\n\tpublic:\r\n\t\t\/\/----------------------------\r\n\t\t\/\/----- PUBLIC VARIABLES -----\r\n\t\t\/\/----------------------------\r\n\r\n\tprivate:\r\n\t\t\/\/---------------------------\r\n\t\t\/\/----- PRIVATE OBJECTS -----\r\n\t\t\/\/---------------------------\r\n\r\n\tpublic:\r\n\t\t\/\/-------------------------\r\n\t\t\/\/----- PUBLIC EVENTS -----\r\n\t\t\/\/-------------------------\r\n\r\n\t};\r\n}\r\n<\/code><\/pre>\n<h5>In the new .cpp file add this to the top after:<\/h5>\n<pre><code>\r\n#include \"StdAfx.h\"\r\n#include \"MyClassFilename.h\"\r\n\r\nnamespace OurLibraries\r\n{\r\n\t\/\/*********************************\r\n\t\/\/*********************************\r\n\t\/\/********** CONSTRUCTOR **********\r\n\t\/\/*********************************\r\n\t\/\/*********************************\r\n\tMyClass::MyClass(void)\r\n\t{\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>(Using namespaces are not needed in .cpp file as the .h file is included):<\/p>\n<h5>Rules:<\/h5>\n<pre><code>\/*\r\nFunctions should be named as follows:\r\n\tvoid ClassName::FunctionName (void) \/\/(The namespace name is not needed but the class name is)\r\n\r\nDefine functions in the header file as follows:\r\n\tvoid FunctionName (void);\r\n\tor\r\n\tvoid ClassName::FunctionName (void);\r\n\tor\r\n\tstatic void FunctionName (void);\t\/\/A static funciton for the class (static included here - not in function itself)\r\n*\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To create A new class, which will create the .cpp and .h files: Project &gt; Add Class &gt; C++ Class Typically: Specify the class name.\u00a0 You don&#8217;t need to provide a base class. Select public and select managed. In the new .h file add the following: The namespace can be a distinct name, or for [&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-75","post","type-post","status-publish","format-standard","hentry","category-classes-objects-struct"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/75","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=75"}],"version-history":[{"count":22,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":1143,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/75\/revisions\/1143"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}