0

I am trying to learn C++, and it seems a bit like C#, but I don't get how I am supposed to make variables, and can't see the problem.

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;
        }
    }

When I look at C#, it should be that I write the variables above the MyForm(void), but that doesn't seem to be the case here, I get the error:

System::Net::IPEndPoint::IPEndPoint' : no appropriate default constructor available

And when searching for it, I don't see the problem I am facing, but other stuff, so I am guess I am implementing this wrong.

Mat
  • 202,337
  • 40
  • 393
  • 406
Zerowalker
  • 761
  • 2
  • 8
  • 27
  • IPEndPoint(void) does not exist. You need to initialize it with some default. – SinisterMJ Aug 09 '13 at 13:53
  • 4
    For what is worth, you are using C++/CLI which is a Microsoft extension thingy. If what you want to learn is really C++, start here: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list (and in that case, your first task is to stop thinking "C++ seems a bit like C#" because that doesn't help at all) – R. Martinho Fernandes Aug 09 '13 at 13:55
  • 1
    Also, this isn't exactly C++. This is C++/CLI. So searching for C++ IPEndPoint help probably wont return a lot of results. – Inisheer Aug 09 '13 at 13:55
  • Wait, so C++ and C++/CLI is different stuff;S? Cause i want to have a winform, makes things so much easier, and work with it like C#. – Zerowalker Aug 09 '13 at 13:56
  • 2
    If you want to work with it as if it was C#, why aren't you just using C#? – Bojangles Aug 09 '13 at 13:57
  • Some stuff doesn´t exist in C# that i want to use, so i have to use C++, else i wouldn´t care about it. – Zerowalker Aug 09 '13 at 13:58
  • @user2587718 Out of curiosity, what doesn't exist in C# that you need? – Inisheer Aug 09 '13 at 14:47

1 Answers1

2

IPEndPoint and TcpListener and .NET reference types so you need to use the "hat":

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

then, you dynamically allocate them using gcnew.

NOTE: Neither class has a default constructor.

Sean
  • 60,939
  • 11
  • 97
  • 136
  • So, if i use this, i can use it like in C#? Making a variable, using the variable when i want etc? – Zerowalker Aug 09 '13 at 14:01
  • Pretty much, but as someone has pointed out, if you want to be like C# then you are better off using C# instead of C++ – Sean Aug 09 '13 at 14:02
  • Nice, but will CLI cause any troubles for me? I mean, do i have to work without Winform without CLI? And sadly, C# doesn´t have some stuff that i need, "Libjpeg" so i have not much choice but to use it. Or making a wrapper, which i can´t as i don´t know C++. – Zerowalker Aug 09 '13 at 14:04
  • If you don't know C++ then you're going to have a hard time doing C++/CLI. My google skill show me that someone has done a .NET wrapper for libjpeg (http://bitmiracle.com/libjpeg/). It might be worth a look. – Sean Aug 09 '13 at 14:06
  • What i meant was if it was even worth getting into CLI, and my google skills tells me it´s a "special" language, and i should try C++ instead. So guess i will have to let it be, pure C++ without WinForm and stuff will be to hard for me. And that .NET wrapper is sadly extremely old and doesn´t seem to have that good performance either. Thanks for the link though. – Zerowalker Aug 09 '13 at 14:20