Here is my problem.

I have a class Template define like this.

// File Vecteur.h
template<class Elem>
 class Vecteur : public AdenEtEve
{
    public :
        ...
        BOOL bInserer (Elem &elemAInserer, MOT32 wIndice);`
        ...

    protected:
        Elem elem;
        Elem *pElem;
        MOT32 wNbElem;
}
        
template<class Elem>
BOOL Vecteur<Elem>::bInserer (Elem &elemAInserer,
                                                    MOT32 wIndice)
{
    BOOL bResultat = FAUX;
    Elem  *pelemTampon;

    // Adjust insertion point if necessary
    if (wIndice > wNbElem)
        wIndice = wNbElem;

    // Add space for new vector
    pelemTampon = new Elem [wNbElem + 1];
    if (pelemTampon)
    {
        Elem *pelemCible, *pelemSource;

        pelemCible = pelemTampon;
        pelemSource = pelem;

        // Add items that are before insertion point
        MOT32 w = wIndice;
        while (w--)
            *pelemCible++ = *pelemSource++;

        // Add the new one
        *pelemCible++ = elemAInserer;

        // Add the rest of elements
        w = wNbElem - wIndice;
        while (w--)
            *pelemCible++ = *pelemSource++;

        if (pelem != NULL)
            delete [] pelem;

        pelem = pelemTampon;
        wNbElem++;

        bResultat = VRAI;
    }
    return bResultat;
}

I use this class template in a cpp file like this

// OneFile.cpp
void RISyntaxeALCIDSICC::MemoriserGarniture (MOT16 &wIndice)
{
    Vecteur<char> *povbGarniture;
    Vecteur<Vecteur<char> *> ovpovbGarniture;

    ....

    // Get some memory space
    povbGarniture = new Vecteur<char>;

    ....

    for (n = 0; n < nLong; n++)
    {
        // This call actually work    
        povbGarniture -> bInserer ((char) szTampon [n]);
    }

    ....

    // This call is generating the link error
    ovpovbGarniture. bInserer (povbGarniture);

    delete povbGarniture;
}

Why do I got this link error:
Error: Unresolved external 'Vecteur<Vecteur<char>*>::bInserer(Vecteur<char>*&,unsigned long)' referenced from module sas\RI Presentateur ALCIDSICC.cpp

Thanks in advance
Martin

Because as of right now you have to include the definition of the template class in the same file as the template header. If your compiler supports the
keyword export, then you can separate them.

The declaration and the definition are in the same file.

I want to understand why the first call to bInserer () is working and the next call to bInserer () is giving me a link error ?

Thanks

Sorry but the code you've posted is somewhat vague/insufficient.

By looking at it, even the

>> povbGarniture -> bInserer ((char) szTampon [n]);

should fail. Are you sure that you posted portion of the header file that you are actually using (note that the class declaration is missing the ending brace)?

[EDIT]
Perhaps compile the code with another compiler, if you have one handy.

To fix my problem I have force the use of the member function bInserer() from an temp variable Vecteur<Vecteur<char>*> .

I have done this in the constructor of my class using this kind of vector

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.