1
Sometimes I find myself in situations like this:
#ifndef CRIARVENDA_H
#define CRIARVENDA_H
#include <QDialog>
#include "cliente.h"
namespace Ui {
class CriarVenda;
}
class CriarVenda : public QDialog
{
Q_OBJECT
public:
explicit CriarVenda(QWidget *parent = 0);
~CriarVenda();
private:
Ui::CriarVenda *ui;
Cliente *cliente;
};
#endif // CRIARVENDA_H
in this case
namespace Ui {
class CriarVenda;
}
A kind of prototype of a class is created that will still be created which does not make much sense.
In this case it still doesn’t make sense yet, where it creates a "Prototype class"
#ifndef CPU_HPP
#define CPU_HPP
#include <array>
#include <cstdint>
#include <functional>
class GameBoy;
Creates a pointer to it
GameBoy* gameboy;
public:
CPU( GameBoy& core );
#include "GameBoy.hpp"
#include "CPU.hpp"
#include "RAM.hpp"
CPU::CPU( GameBoy& core ) :
gameboy( &core ) {
initOpcodeArray();
}
std::uint8_t CPU::readMem( std::uint16_t address ) {
gameboy->ram.readMem( address );
}
void CPU::writeMem( std::uint16_t address, std::uint8_t value ) {
gameboy->ram.writeMem( address, value );
}
Then call up the class members.
What’s the name of it? I’m looking at some C++ books that I have and I don’t see anything like it, and what’s the point?
Of course it makes sense, is for the class to be accessible when
Ui
create the object from Form (which is an Xml that will generate .cpp only in pre-build), this cpp for the form is generated dynamically. And pre-create classes is useful so you need to create a var that type is classGameboy
this in HPP, but the class is only included in CPP, so you already pre-declare and put your var thereclass FooBar {private: Gameboy *var1; }
.– Guilherme Nascimento
What is the name of this technique and what are its advantages?
– Samuel Ives
An advantage is having the accessible pre-class to be able to declare variables of the type of this specific class before including it, but perhaps there should be "more advantages", however if you are going to make a
#include
direct on another . hpp would not have much sense to pre-declare.– Guilherme Nascimento