2
votes

Can somebody help me with this? I'm using Visual Studio 2010 I'm getting this message and I don't know how to solve this.

1> Generating Code...

1>dct.obj : error LNK2019: unresolved external symbol "public: __thiscall Amostras::Amostras(class std::basic_string,class std::allocator >)" (??0Amostras@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main

1>C:\Users\redneck\documents\visual studio 2010\Projects\dct\Debug\dct.exe : fatal error LNK1120: 1 unresolved externals

Here is some of the *.cpp file:

class Amostras {
public:
    int original[10][257];
    int idct[10][257];
    float dct[10][257];
    int grupos;

Amostras::Amostras(void)
    {
    for (int i=0;i<10;i++)
    {
        this->original[i][0]=0; 
        this->dct[i][0]=0.0;
        this->idct[i][0]=0;
        }
        this->grupos=0;
    }

Amostras::Amostras(string arquivo)
{
    int n_samples=0,linha=0,coluna=0;
    int cont;
..

and here is the *.h

class Amostras {
public:
    int original[10][257];
    int idct[10][257];
    float dct[10][257];
    int grupos;

    Amostras::Amostras();
    Amostras::Amostras(string arquivo);
    void Amostras::mostra(void);
};

main

int main(void)
{
    Amostras *amostra = new Amostras("in.txt");
    dct(amostra,0);
    show(amostra,0);
    amostra->mostra();
    return 0;
}

hope it helps, i'm running out of options here :(


Solution:

So what I did was just putting the class just in *.h and then including the *.h in the class *.cpp that only has the methods and functions of that class. It worked!

2
See templatetypedef's answer, but if you want a more specific answer then post your code. In the meantime you can read this for more information on LNK2019: msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspxJBentley

2 Answers

1
votes

This linker error usually means that you have prototyped a function but forgotten to define it. Make sure that you have implemented the function

Amostras::Amostras(string arg);

somewhere, and that when you were linking your code that the object file containing that implementation was linked in.

Hope this helps!

0
votes

you forgot to define the Amostras::Amostras(string arg); though declared in your *.h file

Amostras::Amostras(string arg)
{
}

copy the above code in your *.cpp file

OR

you can also do this by commenting the line from your *.h file.

//Amostras::Amostras(string arg);

whoa! do you have a *.h file ? if you are working in only *.cpp then lemme know.