To create A new class, which will create the .cpp and .h files:
Project > Add Class > C++ Class
Typically:

Specify the class name.  You don’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 classes that are part of a main ap you can just use the ap’s namespace name:


#pragma once

//----- NOTES -----
//
//USING THIS CLASS IN A PROJECT:-
/*
//TOP OF YOUR FILE
#include "MyClass.h"
//USING NAMESPACES
	using namespace OurLibraries;
//IN YOUR DECLARATIONS:
	private: MyClass ^MyClass1;
//IN YOUR CONSTRUCTOR
	MyClass1 = gcnew MyClass();
//START USING
	MyClass1->#();
*/

namespace OurLibraries
{

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;

	public ref class MyClass
	{
	private:
		//---------------------------
		//----- PRIVATE DEFINES -----
		//---------------------------

	private:
		//-----------------------------
		//----- PRIVATE FUNCTIONS -----
		//-----------------------------

	public:
		//----------------------------
		//----- PUBLIC FUNCTIONS -----
		//----------------------------
		MyClass(void);

	private:
		//-----------------------------
		//----- PRIVATE VARIABLES -----
		//-----------------------------

	public:
		//----------------------------
		//----- PUBLIC VARIABLES -----
		//----------------------------

	private:
		//---------------------------
		//----- PRIVATE OBJECTS -----
		//---------------------------

	public:
		//-------------------------
		//----- PUBLIC EVENTS -----
		//-------------------------

	};
}
In the new .cpp file add this to the top after:

#include "StdAfx.h"
#include "MyClassFilename.h"

namespace OurLibraries
{
	//*********************************
	//*********************************
	//********** CONSTRUCTOR **********
	//*********************************
	//*********************************
	MyClass::MyClass(void)
	{
	}

}

(Using namespaces are not needed in .cpp file as the .h file is included):

Rules:
/*
Functions should be named as follows:
	void ClassName::FunctionName (void) //(The namespace name is not needed but the class name is)

Define functions in the header file as follows:
	void FunctionName (void);
	or
	void ClassName::FunctionName (void);
	or
	static void FunctionName (void);	//A static funciton for the class (static included here - not in function itself)
*/
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *