Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

GCC 3.4.5 compile error

(1/1)

bean:
hey guys, i dont know where to put this.i have looked in the gnu gcc compiler site and i went lost.

i have an issue, where i cant seem to compie a very simple tempate class. im using gcc 3.4.5 with mingw.

here is my class:
#ifndef TEST_H
#define TEST_H

template <class T>
class test
{
    // variable
   T *_linkedList;
   unsigned int _count;
   unsigned int _capacity;

    public:
        test()
        {
            _linkedList = new T[10];
            memset(_linkedList, 0, 10);
            _count = 0;
            _capacity = 10;
        }

        virtual ~test()
        {
        }

        unsigned int GetCount()
        {
            return _count;
        }

        T Get(int index)
        {
            if( index >= 0 && index <= _count )
                return _linkedList[index];
            else
               return _linkedList[_count-1];
        }

        void Add(T object)
        {
            if( _count+1 <= _capacity-5 )
                _linkedList[_count++] = object;
        }

    protected:
    private:
};

#endif // TEST_H

and when i come to use it:
test<int> t = test<int>();
   t.Add(0);
   t.Add(1);
   t.Add(2);
   int i = t.Get(1);

i get the "ïnstantiated from here" compile error on line "int i = t.Get(1);". I cant see where i am going wrong.

sorry is this is in the wrong place, but i dont know where to podt it.

thxxx

mandrav:

--- Quote ---i get the "ïnstantiated from here" compile error on line "int i = t.Get(1);". I cant see where i am going wrong.

sorry is this is in the wrong place, but i dont know where to podt it.
--- End quote ---

Yes, this is the wrong place and yet you didn't even bother to post the exact error messages...  :?:

thomas:

--- Code: ---test<int> t = test<int>();
   t.Add(0);
   t.Add(1);
   t.Add(2);
   int i = t.Get(1);

i get the "ïnstantiated from here" compile error on line "int i = t.Get(1);"
--- End code ---
I am surprised you get that far at all, since you don't have test::operator() declared in your template. If that is a verbatim copy of your code, it should already fail at test<int> t = test<int>()...
Quite likely, you forgot to put a new in there.

But nevertheless, it does not seem related to Code::Blocks.

bean:
sorry guys. the error was totally miss leading. appearently i was comparing an int with an unisnged int variable.  :(

that was the problem.

sorry for any disturbance.

thx

Navigation

[0] Message Index

Go to full version