Page 1 of 1

Forward-Declaration of IGUIImage impossible?

Posted: Tue Jun 27, 2017 4:24 pm
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
 
};

Re: Forward-Declaration of IGUIImage impossible?

Posted: Tue Jun 27, 2017 4:30 pm
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.

Re: Forward-Declaration of IGUIImage impossible?

Posted: Tue Jun 27, 2017 4:53 pm
by Notion
Thanks, works just fine now :)

Re: Forward-Declaration of IGUIImage impossible?

Posted: Tue Jun 27, 2017 7:34 pm
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.