Jump to content

  • Log In with Google      Sign In   
  • Create Account


Cannot convert parameter error occuring when working with polymorphism, class-hierarchies, and pointers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 StakFallT   Members   -  Reputation: 245

Like
0Likes
Like

Posted 03 September 2012 - 12:46 PM

Ok quick question. I'm running into an error, essentially a "cannot convert parameter 1 from '<base_blah *>' to '<derived_blah *>' error. (Error C2664). I put together some pseudo-code that is basically a really stripped down version of the code I'm working on, but I think it provides a basic idea of what I'm trying to do and the specific line the specific error occurs at. The code is located here: http://ideone.com/FO5Yu

Please keep in mind, again, class names have been generalized, some functions that are called have been taken out (As they don't add anything to the example), and I may even be missing a few virtual function placements in the derived stuff. What I'm specifically interested in is line 60. That's where the specific error occurs, so please exclude things like design, missing function layouts etc. from any examinations. I'm looking for help on the error, not critique (Especially since it's pseudo-code ;) In the actual code a lot of the stuff is in place and correct but the error I mentioned occurs, hence the reason for the whole post and I beleive it's something very specific; like I can't do what I'm trying to do or something (Which I think I actually can on this or something pretty close...) If anything is unclear about what I'm trying to accomplish, don't hesitate to ask and I'll try to clear it up Posted Image Thanks in advance!

-- StakFallT

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 10591

Like
0Likes
Like

Posted 03 September 2012 - 01:03 PM

It would be better for all if you were to post a piece of code that we can compile ourselves and that shows the problem. The more stuff you remove from the code the better, so just post a minimal example (as in, if you removed anything else, you couldn't show us the problem).

Some idea of what the code is supposed to accomplish would be good. Since it's not working code, we can't figure out what it's supposed to do based on what's written there.

Are you by any chance trying to have a virtual function that can be specialized for several of its arguments? You may want to look up "double dispatch".

#3 StakFallT   Members   -  Reputation: 245

Like
0Likes
Like

Posted 03 September 2012 - 02:14 PM

Yeah, that's exactly where I started, was double dispatch. Well technically I started with the visitor pattern, but explanations I got on the dispatch mechanism seemed to differ. Some explanations seemed to imply that double dispatch, is essentially a pipeline of and accept and then visit callback starting with the accept that then used another accept and a visit ; whereas other dispatch explanations seemed to explain double dispatch as two parameters on the visit argument (Which I think is what you're referring to). Either way, I looked at it, and it just wouldn't work with a vistor pattern. Hard to explain, but for example on an expression tree, if you have a node base, then a nodeleaf (With like bool, char, etc under that), and an Op node (With like add, sub, etc...) under the node base also, the accept methods would be on the bool, char stuff, so calling from the add,sub, etc classes would cause a call to the proper datatype class fine and dandy, but then the visit call back would only be possibly-able to return, basically, "this" (Which would be a bool class or char class etc) i.e. one-half of what's needed (Since an op is not just a single operand, but two). So I had to nix the idea of the accept/visit pattern and roll the eval into the sub,add,mult, etc classes (Where the left and right nodes are stored) with the specific datatype classes handling just things like either emitting string output or returning its value by actual type (Not cBool, but actual bool, etc) as a void pointer and casting it to bool (Which, using deductive reasoning in my design is actually as safe as it can be made). But I'll see what I can do about putting together something that actually compiles (Well, up until the error that is :P )

#4 StakFallT   Members   -  Reputation: 245

Like
0Likes
Like

Posted 03 September 2012 - 02:47 PM

Ok I remade the test case, it's essentially my actually code stripped down to a single datatype (As the others would just bloat the example). Original class names are left intact, virtual function layouts should be the same. Only one question though, would you mind if I PM'ed you the link? It's going to be going into a commercial product, and I'd rather not plaster code from it wide-open.

#5 Álvaro   Crossbones+   -  Reputation: 10591

Like
0Likes
Like

Posted 03 September 2012 - 08:00 PM

I'm not a big fan of doing things via PM. I help out in these forums as some sort of donation of time to the community, and I would rather it help as many people as possible. If we do this through PMs, it will only help you.

But if that's the only way that works for you, PM me the link and I'll take a look. No promises, though.

Edited by alvaro, 03 September 2012 - 08:01 PM.


#6 StakFallT   Members   -  Reputation: 245

Like
0Likes
Like

Posted 03 September 2012 - 08:49 PM

I agree, I like others learning from what I'm working on. My fear is the person that just does a drive-by (That you don't know about) and copy and pastes my code into their project. That's why I did an example case... I mean I don't think it would happen as the Gamedev has always been great; however there's always that one person that comes along, in anything, and makes the exception... I guess nm. I'll continue to try to work it out on my own.

#7 e‍dd   Members   -  Reputation: 2097

Like
0Likes
Like

Posted 04 September 2012 - 04:50 PM

My fear is the person that just does a drive-by (That you don't know about) and copy and pastes my code into their project. That's why I did an example case...


Your stripped-down code should end up being even smaller than the example case.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS