Ok so Im writing a program with SFML that requires more than one window, creating another is as easy as making a virtual function like this:
virtual int Run (sf::RenderWindow &Screen) = 0;
However when I run my program it says:
||=== Build: Debug in SFML Multiple Windows (compiler: GNU GCC Compiler) ===|
C:\Users\thund_000\Desktop\SFML Multiple Windows\main.cpp||In function 'int main()':|
C:\Users\thund_000\Desktop\SFML Multiple Windows\main.cpp|19|error: cannot declare variable 'strct' to be of abstract type 'Strct'|
C:\Users\thund_000\Desktop\SFML Multiple Windows\struct.h|4|note: because the following virtual functions are pure within 'Strct':|
C:\Users\thund_000\Desktop\SFML Multiple Windows\struct.h|8|note: virtual int Strct::Run(sf::RenderWindow&)|
C:\Users\thund_000\Desktop\SFML Multiple Windows\main.cpp|21|error: too many arguments to function 'void MainGame()'|
C:\Users\thund_000\Desktop\SFML Multiple Windows\Prototypes.h|7|note: declared here|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
So I made a test program and here is the code:
Main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Prototypes.h"
#include "struct.h"
using namespace std;
Strct::Strct(sf::RenderWindow &WINDOW, sf::VideoMode &VIDEOMODE): window(WINDOW), videoMode(VIDEOMODE)
{
}
int main()
{
sf::RenderWindow win;
sf::VideoMode vMode;
Strct strct(win, vMode);
MainGame(strct);
}
|
Window2.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Prototypes.h"
using namespace std;
void win2(Strct &strct)
{
sf::RenderWindow secondWindow(sf::VideoMode(800, 600), "Second Window");
while(secondWindow.isOpen())
{
secondWindow.clear();
sf::Event event2;
while(secondWindow.pollEvent(event2))
{
switch(event2.type)
{
case sf::Event::Closed:
{
secondWindow.close();
}
}
}
secondWindow.display();
}
}
|
Prototypes.h
1 2 3 4 5 6 7 8 9
|
#ifndef PROTOYTYPES_H_INCLUDED
#define PROTOYTYPES_H_INCLUDED
#include "struct.h"
void win2(Strct &strct);
void MainGame();
#endif // PROTOYTYPES_H_INCLUDED
|
struct.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#ifndef STRUCT_H_INCLUDED
#define STRUCT_H_INCLUDED
struct Strct
{
Strct(sf::RenderWindow &WINDOW, sf::VideoMode &VIDEOMODE);
virtual int Run (sf::RenderWindow &Screen) = 0;
sf::RenderWindow &window;
sf::VideoMode& videoMode;
};
#endif // STRUCT_H_INCLUDED
|
window1.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Prototypes.h"
void MainGame()
{
sf::RenderWindow mainWindow(sf::VideoMode(800, 600), "Main Window");
while(mainWindow.isOpen())
{
mainWindow.clear();
sf::Event event;
while(mainWindow.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
mainWindow.close();
}break;
}
}
mainWindow.display();
}
}
|