win表单C ++ / CLI如何从头文件中使用.cpp类

时间:2011-10-06 14:18:17

标签: c++ winforms c++-cli

您好我有样品

#include "stdafx.h"
using namespace System;

ref class RefClass 
{
public:
    int X;

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

如何在Form1.h中使用此类?与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) {

         }

第二,我应该在.h中放置RefClass代码?还是.cpp?

1 个答案:

答案 0 :(得分:1)

  • 创建一个RefClass.h文件,您将在其中放置类声明。
  • 创建一个RefClass.cpp文件,您将放置类定义。实施。
  • 要在任何其他课程中使用它,您必须包括 首先是RefClass.h,然后你可以auto refClass = gcnew RefClass();