How can i remove this class, whats the problem?

Started by
8 comments, last by Zahlman 15 years, 11 months ago
(all the code and classes are my own, which makes this question look more stupid) http://nopaste.com/p/aP1gFCFtm if you look at main.cpp you'll see the class CSubTreeIterator_STL it looks like i can do without that class. I tried removing it but i get compile errors. It has something to do with conversion but i dont know why or how the extra class fixed that conversion. -Edit- No errors in this paste. When i try to remove that class there are errors [Edited by - EccentricSight on May 6, 2008 2:22:11 PM]
Advertisement
Post the exact errors and the lines that cause them (not just line numbers, the actual lines).
I don't see your main() function in what you call "main.cpp". Where does all this stuff get used?
There is a lot of source that goes with this. I removed except for what is needed to compile. There is no need for the rest of the source. The paste compiles and what i want to know is how can i remove the CSubTreeIterator_STL class without getting compile errors.
post the actual compiler errors. my brain can't compile your code

-me
Ok. It's easy:

Since none of the code is ever used, none of it needs to be there.
:| I cant believe people want more code AND compile errors along with the job of cleaning code instead of just cleaning code. Ok, here you go. the source http://nopaste.com/p/aMPorJBFp

the error (its on the line with return &subIt )

error C2440: 'return' : cannot convert from 'CSTLfiterator<_t,_t2,_t3> *__w64 ' to 'Cfiterator<_t> *'        with        [            _t=std::vector<CDirItems *>,            _t2=std::_Vector_const_iterator<CDirItems *,std::allocator<CDirItems *>>,            _t3=CDirItems *        ]        and        [            _t=CTreeFIterator<const char *> *        ]        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


enjoy ;P
It means exactly what it says. After making the changes to your code implied by the comments, subIt is a member of type CSTLfiterator<vector<CDirItems*>, vector<CDirItems*>::const_iterator, CDirItems*>. According to the class definition, that inherits from Cfiterator<CDirItems*>. Yet, you're trying to return its address from a method whose return value is the address of a Cfiterator<CTreeFIterator<const char *> *>, which is a completely different type. So maybe you need to clarify what you're trying to do here.
>So maybe you need to clarify what you're trying to do here.

Thats exactly why i didnt want to post the bug. People will think i am trying to solve it and not read my question

>According to the class definition, that inherits from Cfiterator<CDirItems*>. Yet, you're trying to return its address from a method whose return value is the address of a Cfiterator<CTreeFIterator<const char *> *>

CDirItems inherits CTreeFIterator<const char *>. So both of these are or should be Cfiterator<CTreeFIterator<const char *> *>.

If you look at the first paste you'll see that CSubTreeIterator_STL does nothing with itData. So i should be able to skip the class entirely (look at it, it does nothing) but i get that error instead. Why?
---------------------------------------------

For guys who are reading this part.
This is the first paste where everything works correctly http://nopaste.com/p/aP1gFCFtm
I want to remove class CSubTreeIterator_STL, guys kept bugging me for an error so i made this paste http://nopaste.com/p/aMPorJBFp . It seems like it doesnt like to mix Cfiterator<CDirItems*> and Cfiterator<CTreeFIterator<const char *> *> which both are Cfiterator<CTreeFIterator<const char *> *> . Now iam trying to understand why it works when i have the CSubTreeIterator_STL which does nothing and does not work w/o that class.
Quote:Original post by EccentricSight
CDirItems inherits CTreeFIterator<const char *>. So both of these are or should be Cfiterator<CTreeFIterator<const char *> *>.


Nope, sorry. It isn't. That's your problem. Templates don't work that way. A Cfiterator over derived is not a kind of Cfiterator over base. In general, X<B> and X<D> have nothing to do with each other, inheritance-wise, even if D is derived from B. The missing class is, apparently (although I'm too busy with other stuff right now to grok it fully) a wrapper which causes this relationship to exist.

This topic is closed to new replies.

Advertisement