2

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!

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Éder John
  • 21
  • 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: http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx – JBentley Apr 13 '12 at 18:38

2 Answers2

1

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!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
0

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.

jeet.chanchawat
  • 5,842
  • 5
  • 38
  • 59
  • I have and *.h file with all the prototypes from my *.cpp file. – Éder John Apr 13 '12 at 18:48
  • ok, and did it worked ? try to make a inline constructor if you are not using it. – jeet.chanchawat Apr 13 '12 at 18:51
  • It didn't worked, i have all my class defined in *.cpp, with all constructors (2), variables, and just one function. In my *.h I have prototypes of the constructors, variables, and the function as well. I'm including in my other file the *.h. – Éder John Apr 13 '12 at 18:58