Jump to content
  • Advertisement
Sign in to follow this  
reaptide

This pointer wierdness

This topic is 4846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, I'm working on the rendering part of my code and I'm borrowing a few ideas from the Ogre engine. One of those ideas is the it attaches viewports to the render target. The problem that I'm having is that I can't seem to pass a this pointer to a method. I want to store a pointer to the render target in the viewport. The render target is responsible for creating viewports and it passes a pointer to its to the newly created viewport. Or at least that's what I hoping to do. Here is the code of my AddViewport() method:
Viewport *RenderTarget::AddViewport(Camera *AttachedCamera, float X, float Y, float Width, float Height, int ZOrder)
    {
        // Make sure a viewport with this Z-Order doesn't already exist
        ViewportList::iterator iter = m_ViewportList.find(ZOrder);

        // Dump an error if it does exist
        if (iter != m_ViewportList.end())
        {
            // Build an error
            std::stringstream ErrorString;
            ErrorString << "RenderTarget::AddViewport() - Cannot add a new viewport. A viewport with a Z-Order of ";
            ErrorString << ZOrder;
            ErrorString << ", already exists.";

            throw std::runtime_error(ErrorString.str());
        }

        // Create a new viewport
        Viewport *VPort = new Viewport(AttachedCamera, this, X, Y, Width, Height, ZOrder); //<-- The Problem!!

        // Add the viewport to the viewport list
        m_ViewportList.insert(ViewportList::value_type(ZOrder, VPort));

        return VPort;
    }


And this is the code of the Viewport's constructor:
Viewport::Viewport(Camera *AttachedCamera, RenderTarget *Target, float X, float Y, float Width, float Height, int ZOrder)
    {
        assert(AttachedCamera && "NULL Camera pointer. A viewport must have a valid camera.");
        assert(Target && "NULL RenderTarget pointer. A viewport must be attached to a valid render target.");

        m_AttachedCamera = AttachedCamera;
        m_Target         = Target;

        m_RelativeX      = X;
        m_RelativeY      = Y;
        m_RelativeWidth  = Width;
        m_RelativeHeight = Height;

        m_ZOrder         = ZOrder;

        m_ActualX        = 0;
        m_ActualY        = 0;
        m_ActualWidth    = 0;
        m_ActualHeight   = 0;

        m_ClearColor     = Color(0.0f, 0.0f, 0.0f, 0.0f);
        m_ClearEachFrame = false;

        UpdateDimensions();
    }


The error I'm getting is:
Quote:
C2664: 'Shard::Viewport::Viewport(Shard::Camera *,RenderTarget *,float,float,float,float,int)' : cannot convert parameter 2 from 'Shard::RenderTarget *const ' to 'RenderTarget *'
I tried changing the Viewport constructor to accept a const RenderTarget pointer but that craps out just as badly. I could have sworn that this was possible. I have a feeling that I used to be able to do it in MSVS 6.0, but its not working under 7.0. Anyone know what's up or do I not know my this pointers as well as I thought?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Sfpiano
'this' is a const pointer and your viewport function calls for a non-const RenderTarget

struct R;

struct V {
V( R *r ) : ptr( r ) {}

R *ptr;
};

struct R {
R() {}
V *Add() {
return new V( this );
}
};


int main() {
R r;
r.Add();

return 0;
}

// ----------------------------------
Compiling...
main.cpp
Linking...

test12 - 0 error(s), 0 warning(s)






@reaptide:
Strange. I wonder if there's a naming conflict. Is your forward declaration of RenderTarget in the Shard namespace? If it is, try prefixing RenderTarget *Target with Shard:: in your Viewport constructor.


jfl.

Share this post


Link to post
Share on other sites
Quote:
Original post by jflanglois
@reaptide:
Strange. I wonder if there's a naming conflict. Is your forward declaration of RenderTarget in the Shard namespace? If it is, try prefixing RenderTarget *Target with Shard:: in your Viewport constructor.


Thanks! One small changed fixed everything. I added a foward declaration of the RenderTarget class to the Viewport class's header file and it works now. Looks like it was a naming conflict of some sort.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!