H
H
Hocksten2015-08-14 19:27:05
Command line
Hocksten, 2015-08-14 19:27:05

How to connect a class to a form - C++/CLI?

there is a windowopen.h file

#include <SFML\Graphics.hpp>
#include <string>
 
class WindowOpen{
public:
    int win_width, win_height;
    WindowOpen(int WINW, int WINH)
    {
        win_width = WINW;
        win_height = WINH;
        sf::RenderWindow window(sf::VideoMode(win_width, win_height), "Test");  
};

How can I open a window on a button?
Main file MyForm.h
#include "windowapp.h"
#pragma once

namespace gameengine {

  using namespace System;
        ......................

public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    }
            WindowOpen w(640, 480);
    };
}

I get an error
Ошибка  1   error C2059: синтаксическая ошибка: константа

I'm just learning C++, please help :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-08-14
@Nipheris

1) in the first block of code, you may have missed the closing curly brace, check;
2) if you create a window, then most likely it will live for a relatively long time, and its lifetime will need to be managed manually. This means that it's time for you to figure out what pointers are and manual management of the memory / lifetime of an object (i.e. WindowOpen w (640, 480) is most likely not good)
3) immediately learn to give adequate names to entities in the program. WindowOpen is a function name, not a class name, perhaps you meant just Window.
4) if possible, do not use C++/CLI as a learning language. This is a docking dialect of C ++ for implementing the interaction of systems on top of .net and native ones - even an experienced C ++ developer can get confused in it, beginners cannot even look at it - it kills the soul. That MS on a default offers the project in studio is so historically developed. MS doesn't offer anything adequate for the C++ desktop right now, so my advice to you is either C# + WPF/WinForms or Qt + C++. SFML seems to work fine with Qt .

H
Hocksten, 2015-08-14
@Hocksten

Thank you for the answer, I solved the problem with
A about C ++ CLI, I like it more than QT, but I don’t want to look towards C #, because I need a cross-platform language)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question