Sign in to follow this  
3dmodelerguy

conversion problem

Recommended Posts

ok here is all the code relating to the problem:
template< class cl >
CList::Iterator< cl > CList::CustomList< cl >::Begin()
{
	CList::Iterator< cl > *iterator = new CList::Iterator< cl >();
	return iterator;
} 
template< class iter >
CList::Iterator< iter >::Iterator()
{

}




// in main()
CList::Iterator< int > *iterator = new CList::Iterator< int >();

iterator = intlist->Begin();


this is a error i am getting:
main.cpp(19) : error C2440: '=' : cannot convert from 'CList::Iterator<iter>' to 'CList::Iterator<iter> *'
        with
        [
            iter=int
        ]
        and
        [
            iter=int
        ]
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Build log was saved at "file://c:\Documents and Settings\ryan\My Documents\Visual Studio Projects\CustomList\Debug\BuildLog.htm"
CustomList - 1 error(s), 0 warning(s)


now i have tried everything i can think ok to get this working but nothing seem to help only reverses the order the the error to: main.cpp(19) : error C2440: '=' : cannot convert from 'CList::Iterator<iter> *' to 'CList::Iterator<iter>' can you see any way of fixing this? [Edited by - 3dmodelerguy on May 25, 2005 8:06:17 AM]

Share this post


Link to post
Share on other sites
You made a vital mistake in this function:


template< class cl >
CList::Iterator< cl > CList::CustomList< cl >::Begin()
{
CList::Iterator< int > *iterator = new CList::Iterator< int >();
return iterator;
}


Try replacing the occurences of CList::Iterator< int > with CList::Iterator< cl >.

It probably messes up somewhere, I had the same thing happen to me. Messing a bit around worked. Also, try to work with stack instances of the iterator and overload the operator = on it.

Toolmaker

Share this post


Link to post
Share on other sites
It seems you're returning a pointer (CList::Iterator< int > *) where your function declaration says you're returning a value (CList::Iterator< cl >)

Hope this helps

Eric

Share this post


Link to post
Share on other sites
Yep. You allocate a new thing and return a pointer, and use it like a pointer, so the evidence indicates that's what you want - so the change needs to be to the return type declaration (so it says you're returning a pointer). :)

Although, it looks quite likely to me like you're going to have some problems deleting that object correctly (i.e. exactly once) ;s

Share this post


Link to post
Share on other sites
I fail to see why you dynamically allocate your iterator. What's wrong with

template< class cl >
CList::Iterator< cl > CList::CustomList< cl >::Begin()
{
return CList::Iterator< cl >();
}


And shouldn't you be passing to the constructor some info about the list you're going to iterate over?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this