在/ clr中使用非托管c ++对象

时间:2017-05-15 20:53:27

标签: c++ clr windows-forms-designer

我用c ++编写了类下面的类,我必须将它们实现到Windows窗体中。是否有任何解决方案可以在Windows窗体/ clr类中创建非托管对象?

#pragma once
#ifndef _HOTEL_H
#define _HOTEL_H
#include "Room.h"
#include "Adress.h"
#include "Employee.h"
#include "Apartament.h"
#include "TechnicalRoom.h"
#include "RecreationRoom.h"
#include <vector>
#include <string>


using namespace std;

class Hotel {
protected:
int HotelID, HotelStars, NumberOfEmployee, NumberOfClients, NumberofRooms;
string HotelName;
Adress HotelAdress;
vector <Room*> Rooms;
vector <Person*> People;
public:

//methods
Hotel(int = 3, string = "Hotel");
~Hotel();
string getName();
int getNumberOfClients();
int getNumberOfEmployee();
int getHotelStars();
void changeNumberOfStars(int);
void BookApartament(int, int);
void AddRoom(int);
void DeleteRoom(int);
void AddEmployee();
void DeleteEmployee(int);

friend ostream & operator<< (ostream &out, Hotel &h);
friend ref class MainWindow;
};
#endif

1 个答案:

答案 0 :(得分:0)

这听起来像你可能想要的东西:

namespace SomeCompany
{
    public ref class Hotel
    {
        ::Hotel* pHotel;
        public:
            Hotel() : pHotel(new ::Hotel()) {}
            ~Hotel() {
               delete pHotel;
               pHotel = nullptr;
            }
            !Hotel() {
               delete pHotel;
            }
            // ... etc. ... 
    };
}

有关详细信息,请参阅How to: Wrap Native Class for Use by C#