Forward-Declaration of IGUIImage impossible?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Notion
Posts: 9
Joined: Mon Mar 20, 2017 11:00 pm

Forward-Declaration of IGUIImage impossible?

Post by Notion »

Is there any reason why I cant forward declare UGUIImage and ITexture? Compiler wont compile this, telling me "IGUIImage: ambiguous symbol".

Code: Select all

#pragma once
#include <string>
 
 
class IGUIImage;
class ITexture;
 
class CustomButton 
{
public:
    CustomButton(IGUIImage*);
    ~CustomButton();
 
    //zum laden der Grafik und bestimmen der anweisung
    int graphicsAndActionID = 0;
 
    IGUIImage *image;
 
    ITexture *basicTexture;
    ITexture *disabledTexture;
    ITexture *hoverTexture;
 
    std::string tooltiptitle;
    std::string tooltipbody;
 
    bool disabled;
 
    void update(); //check if action changed from ready to not-ready
 
    void hover(); //return tooltip, switch to hover
    void unfocus(); //basic texture
 
    int clicked(); //returns id
 
};
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Forward-Declaration of IGUIImage impossible?

Post by MartinVee »

Ambiguous doesn't mean you can't. It's just that the compiler found (possibly) multiple declarations of IGUIImage, or it doesn't know from which namespace your IGUIImage (or ITexture) comes from.

Try adding the namespace first :

Code: Select all

 
class irr::gui::IGUIImage;
class irr::video::ITexture;
 
Don't forget to add the namespace each time you reference a IGUIImage or a ITexture.
Last edited by MartinVee on Tue Jun 27, 2017 5:38 pm, edited 1 time in total.
Notion
Posts: 9
Joined: Mon Mar 20, 2017 11:00 pm

Re: Forward-Declaration of IGUIImage impossible?

Post by Notion »

Thanks, works just fine now :)
realmsinthemists
Posts: 28
Joined: Mon Mar 27, 2017 7:29 am

Re: Forward-Declaration of IGUIImage impossible?

Post by realmsinthemists »

Just a quick tip on forwarding:

Sometimes I couldn't find back where I had forwarded a class, so it kept on existing while I had renamed the class. Very annoying.

Rather then add a line which say: class ThisOrThat; you can declare it within a class or function scope too. And off course at the first occurrence is enough. When I include this header file into another, I tend to forward redeclare/reforward declare (uh?!) I tend to reDO it again.

Using your code:

Code: Select all

 
#pragma once
#include <string>
 
 
class CustomButton
{
public:
    CustomButton( class irr::gui::IGUIImage*);
    ~CustomButton();
 
    //zum laden der Grafik und bestimmen der anweisung
    int graphicsAndActionID = 0;
 
    IGUIImage *image;
 
    class irr::gui::ITexture *basicTexture;
    ITexture *disabledTexture;
    ITexture *hoverTexture;
 
This way you (well me actually) keep it organised. What works for you is most useful, I'd guess.
For my end result I am working on:
- Volume Voxel System
- Simple light weight physics engine
Post Reply