Jump to content
  • Advertisement
Sign in to follow this  
chad_420

Casting, Templates and References oh my.

This topic is 4884 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

Im attempting to put together an engine based on enginuity articles here. To start I've gone through upto article 4 and accordfing to that should be able to build my engine with what was covered so far. One part is hanging me up. I have this function:
bool CKernel::AddTask(CMMPointer<ITask> &t)
{
  if(!t->Start())return false;

  //keep the order of priorities straight
  std::list< CMMPointer<ITask> >::iterator it;
  for(it=taskList.begin();it!=taskList.end();it++)
  {
    CMMPointer<ITask> &comp=(*it);
    if(comp->priority>t->priority)break;
  }
  taskList.insert(it,t);
  return true;
}


the problem Im having with it is as so: CKernel::GetSingleton().AddTask(CMMPointer<ITask>(soundTask)); wont compile giving me the error: D:\Src\engine\CApp.cpp no matching function for call to `CKernel::AddTask( CMMPointer<ITask>)' error D:\Src\engine\CKernel.h:33 candidates are: bool CKernel::AddTask(CMMPointer<ITask>&) So i tryed making it jsut take the variable not a reference and it compile, but then I get an access violation that I believe to be related. Any ideas? Has anyone else tryed to put together enginuity on dev-cpp/gcc? Edit more investigation has shown that the access violation is not related, but it still bugs me these errors, just making them not references seems like the wrong approach.

Share this post


Link to post
Share on other sites
Advertisement
The problem is that the temporary value you're passing is considered constant, whereas your function takes a reference to a NON constant.

Since you're creating a copy of the task (or the CMMPointer<ITask> construct anyways, when you call insert), it looks like fixing your problem is simply a matter of changing:

bool CKernel::AddTask(CMMPointer<ITask> &t)

to:

bool CKernel::AddTask(const CMMPointer<ITask> &t)

Any access violation caused by this code would be a bug within CMMPointer, ITask, or whatever called this function (e.g. if it passed a bad argument).

HTH

Share this post


Link to post
Share on other sites
Thanks MaulingMonkey, you nailed it dead on. Now time to hunt down this access violation, it appears to be in CMMPointer.

Share this post


Link to post
Share on other sites
What you are looking for is actually fixing your ()
From making a temporary:
CKernel::GetSingleton().AddTask(CMMPointer<ITask>(soundTask));
To casting your pointer:
CKernel::GetSingleton().AddTask((CMMPointer<ITask>)soundTask);

Share this post


Link to post
Share on other sites
Oh my I didn't catch that! I'm going to have to check that out thanks! Man that could definatly be the source of an access violation methinks.

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!