John
John

Reputation: 874

win forms C++/CLI How to use .cpp class from header

Hello I have sample

#include "stdafx.h"
using namespace System;

ref class RefClass 
{
public:
    int X;

    RefClass(int x)
    {
        X = x;
    }
};

How can I use this class in Form1.h? Like RefClass^ d = gcnew WinFormsTest::RefClass();

public ref class Form1 : public System::Windows::Forms::Form

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

         }

2nd Where i should place RefClass code in .h? or .cpp?

Upvotes: 1

Views: 2017

Answers (1)

Muhammad Hasan Khan
Muhammad Hasan Khan

Reputation: 35136

  • Create a RefClass.h file where you'll put the class declaration.
  • Create a RefClass.cpp file where you'll put the class definition. The implementation.
  • For using it in any other class you have to include RefClass.h first and then you can do auto refClass = gcnew RefClass();

Upvotes: 1

Related Questions