Invalid conversion

Why is this giving me an error? it says invalid conversion from int to int*. not sure why... :S

I bolded where it says the error is, and where it is instantiated from.

Specification
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <class ItemType>
bool DynList<ItemType>::Insert(ItemType item)
{
    
    try
    {
        itArr[length] = item*;    }
    catch(bad_alloc)
    {
        cout << "!@#$, we're out of memory Cap'n, couldn't insert that last one there";
        return false;
    }
    length++;
    return true;
}


Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef DynList_H_2011
#define DynList_H_2011


const int DEFAULT_MAXLENGTH = 10000;

template<class ItemType>
class DynList
{
    public:
        //constructor
        DynList();

        //Destructor
        ~DynList();

        //Action Responsibilities
        bool Insert(ItemType item);
        //Adds Item to List and increments length
        void Delete(ItemType item);
        //Item is removed from list
        void ResetList();
        //current pos is reset to first item
        ItemType GetNextItem();
        //HasNext must be true

        //Knowledge Responsibilities
        int GetLength() const;
        //returns listlength
        bool IsEmpty() const;
        //true if list is empty
        bool IsThere(ItemType item) const;
        //checks to see if item is in list
        bool HasNext() const;
        //checks to see if there is a next item
        int RoomLeft() const;

        private:
            ItemType* itArr = new ItemType[DEFAULT_MAXLENGTH];
            int length;
            int currentPos;
           };

#endif // DynList_H 



Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdlib>
#include "DynList.h"
#include "DynList.cpp" // I know this is weird, but it kept telling me my functions were undefined until I did this. crude, but it works.
using namespace std;

int main()
{
    DynList<int> intArray;
    DynList<double> doubArray;

    int x = 11;
    for (int i = 0; i < 100; i++)
    {
        x+=6;
        intArray.Insert(x);
    }

    double y = 11.11;
    for (int i = 0; i < 100; i++)
    {
        y+= 6.66;
        doubArray.Insert(y);    }


    cout << intArray.GetNextItem();
}
Last edited on
What is item* supposed to do?
I'm basically trying to insert item into the array of itemtypes. I typecasted it as a pointer because it gave me the same error regardless :(
Does this work? itArr[length] = item;
negative. exact same error. honestly i can comment that entire line out and it still does it.
If I change to itArr[length] = item; the code compiles for me so I don't know what could be wrong.
The problem is on line 39 of 'Header'. You have to do the new in your constructor.

In your 'Specification' you can omit that try...catch block since that exception cannot happen there. While it can have an overflow

I think line 39 will work if he use C++11.
Topic archived. No new replies allowed.