Tuesday, September 20, 2005

GCC / C++ oddity

We started using a newer version of GCC (3.4), which is apparently more strict, but something really really weird came up... This code compiles and runs up to GCC 3.3.

Here is part of the actual .h file:

template
class CBContainer
{
protected:
struct Container
{
Container *pNextContainer;
T *pObjects;
int lastSlot;

Container(Container *pPrevContainer, int numObjects)
{
pNextContainer = 0;

if (pPrevContainer)
pPrevContainer->pNextContainer = this;

pObjects = new T[numObjects];
lastSlot = 1;
}
~Container(){ delete [] pObjects; delete pNextContainer; }
int GetSize() const{ return nextSlot + (pNextContainer ? pNextContainer->GetSize() : 0);}
};

.....snip
}

Notice that GetSize() uses 'nextSlot', which is not defined _anywhere_. I tried to simplify it but just a .h with 'int foo() { return undefArg + };' does make the compiler choke.. Maybe the template has something to do with it?

1 Comments:

Blogger jerdavis said...

Since nothing was calling the method, the compiler didn't generate code for it.. The new compiler does.

8:17 PM  

Post a Comment

<< Home