Original Post
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: And this is the code of the Viewport's constructor: The error I'm getting is:
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;
}
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();
}
Quote: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?
C2664: 'Shard::Viewport::Viewport(Shard::Camera *,RenderTarget *,float,float,float,float,int)' : cannot convert parameter 2 from 'Shard::RenderTarget *const ' to 'RenderTarget *'