Skip to main content
GameDev.net gamedev.net
🔒 Locked

This pointer wierdness

Started by reaptide May 11, 2005 at 12:28 AM 3 replies 1k views
Original Post
reaptide
reaptide
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?
Sfpiano
Sfpiano
'this' is a const pointer and your viewport function calls for a non-const RenderTarget
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
jflanglois
jflanglois
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.cppLinking...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.
Arelius
Arelius
You could of course, cast the pointer
reaptide
reaptide
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.