没有变量?

时间:2013-08-09 13:51:50

标签: c++-cli

我正在尝试学习C ++,它看起来有点像C#,但我不知道我应该如何制作变量,并且看不到问题。

public ref class MyForm : public System::Windows::Forms::Form
{
private: TcpListener tcplisten;
private: IPEndPoint adress;
public:
    MyForm(void)
    {
        InitializeComponent();

    }

protected:

    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }

当我查看C#时,应该是我将变量写在MyForm(void)之上,但这似乎不是这里的情况,我得到错误:

  

System :: Net :: IPEndPoint :: IPEndPoint':没有合适的默认构造函数

在搜索时,我没有看到我面临的问题,但是其他的东西,所以我猜我实现了这个错误。

1 个答案:

答案 0 :(得分:2)

IPEndPointTcpListener以及.NET引用类型,因此您需要使用“帽子”:

private: TcpListener ^tcplisten;
private: IPEndPoint ^adress;

然后,您使用gcnew动态分配它们。

注意:两个类都没有默认构造函数。