Author Topic: GCC 3.4.5 compile error  (Read 4322 times)

bean

  • Guest
GCC 3.4.5 compile error
« on: August 17, 2006, 02:55:58 pm »
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

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: GCC 3.4.5 compile error
« Reply #1 on: August 17, 2006, 03:33:58 pm »
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.

Yes, this is the wrong place and yet you didn't even bother to post the exact error messages...  :?:
Be patient!
This bug will be fixed soon...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: GCC 3.4.5 compile error
« Reply #2 on: August 17, 2006, 04:42:08 pm »
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);"
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.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

bean

  • Guest
Re: GCC 3.4.5 compile error
« Reply #3 on: August 17, 2006, 04:48:52 pm »
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