i get an error i dont believe is legit

Klipas.h

#pragma once
#include "ReklaminiaiKlipai.h"
//----------------------------------------------------------
class Klipas
{
public:
static const int CMax = 100;;
private:
ReklaminiaiKlipai Klip[CMax];
int n;
public:
Klipas(): n(0) {}
int Imti() { return n;}
void Dėti(int n) { Klipas::n = n; }
ReklaminiaiKlipai & operator[ ](int n) { return Klip[n]; }
};


ReklaminiaiKlipai.h

#pragma once
#include <string>
using namespace std;
//----------------------------------------------------------
class ReklaminiaiKlipai
{
public: static const int Crez = 100;
private:
string pav, gr;
double truk;
int rezX, rezY;
public:
ReklaminiaiKlipai():pav(""), gr(""), truk(0), rezX(0), rezY(0) { }
void Dėti(string pav, string gr, double truk, int rezX, int rezY);
double ImtiTR() {return truk;}
int imtiRX() {return rezX;}
int imtiRY() {return rezY;}
string Spausdinti();
bool operator <= (const ReklaminiaiKlipai & kitas){
return (truk < kitas.truk ||
truk == kitas.truk && gr < kitas.gr);
}
};


ReklaminiaiKlipai.cpp

#include "ReklaminiaiKlipai.h"
#include "Klipas.h"
#include <sstream>
#include <iomanip>
using namespace std;

void ReklaminiaiKlipai::Dėti(string pav, string gr, double truk, int reX, int rezY)
{
this->pav=pav;
this->gr=gr;
this->truk=truk;
this->rezX=rezX;
this->rezY=rezY;
}

string ReklaminiaiKlipai::Spausdinti()
{
stringstream eil;
eil << left << setw(12) << pav << setw(8) << gr <<
setw(3) << setprecision(2) <<truk << right;
for (int i = 0; i < 2; i++)
eil << setw(6) << rezX << setw(6) << rezY;
eil << endl;
return eil.str();
}



pagrindinis.cpp

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
#include "Klipas.h"
//----------------------------------------------------
const char CDfv[] = "Duom.txt";
const char CRfv[] = "Rezultatai.txt";
//----------------------------------------------------
void Duomenys(Klipas & K);
void Spausdinti(Klipas & K, const string & antraštė);
double Sumuoti(Klipas K);
void Tvarkyti(Klipas & K, Klipas & S, int rezX, int rezY);
void PriskirtiNulius(Klipas & K, int i);
void Trinti(Klipas K);
void Rikiuoti(Klipas K);
//----------------------------------------------------
int main()
{
ofstream fout(CRfv);
fout.close();
Klipas K; // duomenys
Klipas S; // sąrašas
int rezX=1024;
int rezY=512;

Duomenys(K); // skaitomi duomenys
Spausdinti(K, "Pradiniai duomenys");
Tvarkyti(K, S, rezX, rezY);
Klipas Tvarkyti(S);

return 0;
}
//-----------------------------------------------------// Skaitomi pradiniai duomenys į objektą R
void Duomenys(Klipas & K)
{
ifstream fin(CDfv);

bool yra = true;
string pv, gr;
double tr;
int rezX, rezY;
ReklaminiaiKlipai RK;
int nk = 0; // klipu skaitiklis

while (!fin.eof() && yra) { // kol yra duomenų ir jie telpa į masyvą
getline(fin, pv, ','); // įvedami keli žodžiai
fin >> ws; // praleidžiami tarpai
getline(fin, gr, ',');
fin >> tr >> rezX >> rezY;
fin.ignore();
RK.Dėti (pv, gr, tr, rezX, rezY);
if (!fin.eof() && (nk - 1 < Klipas::CMax ))
K[nk++] = RK;
else
yra = false;
}
fin.close();
K.Dėti(nk);
}
//-----------------------------------------------------// Spausdinami objekto R duomenys
void Spausdinti(Klipas & K, const string & antraštė)
{
ofstream fout(CRfv, ios::app);
fout << setw(30) << antraštė << endl;
fout << "------------------------------------------\n";
fout << " Pavardė Vardas Grupė Pažymiai \n";
fout << "------------------------------------------\n";
for (int i = 0; i < K.Imti(); i++)
fout << K[i].Spausdinti();
fout << setw(20) << "Bendra klipų trukmė – " << Sumuoti(K);
fout << "------------------------------------------\n\n\n";
fout.close();
}
//-----------------------------------------------------
double Sumuoti(Klipas K)
{
double suma=0;
for (int i=0; i < K.Imti(); i++)
suma+=K[i].ImtiTR();
return suma;
}

//-----------------------------------------------------
void Tvarkyti(Klipas & K, Klipas & S, int & rezX, int & rezY)
{
int n=0;
int i;
for (i=0; i < n - 1; i++)
if (rezX == K[i].imtiRX() && rezY == K[i].imtiRY()) {
S[n++]=K[i];
PriskirtiNulius(K, i);
Trinti(K);
}
}
//-----------------------------------------------------
void PriskirtiNulius(Klipas & K, int i)
{
K[i].Dėti("", "", 0, 0, 0);
}
//-----------------------------------------------------
void Trinti(Klipas & K)
{
int i=0;
bool yra=true;
while (yra=true) {
while (K[i].ImtiTR() != 0)
i++;
int f=i;
while (K[i].ImtiTR() == 0)
i++;
int l=i;
K[f+1] = K[l];
K[l].Dėti("", "", 0, 0, 0);
for (int i=0; i<K.Imti(); i++);
yra=false;
for (int i=0; i<K.Imti(); i++)
if (K[i].ImtiTR()==0)
for (int j=K.Imti()-1; j>i-1;j--)
if (K[j].ImtiTR()!=0)
yra=true;
}
}
//-----------------------------------------------------
void Rikiuoti(Klipas K)
{
for (int i = 0; i < K.Imti() - 1; i++){
ReklaminiaiKlipai min = K[i];
int im = i;
for (int j = i+1; j < K.Imti(); j++)
if (K[j] <= min){
min = K[j];
im = j;
K[im] = K[i];
K[i]= min;
}
}
}
//-----------------------------------------------------

Output:

1>------ Build started: Project: LD3_111, Configuration: Debug Win32 ------
1> pagrindinis.cpp
1>pagrindinis.obj : error LNK2019: unresolved external symbol "void __cdecl Trinti(class Klipas)" (?Trinti@@YAXVKlipas@@@Z) referenced in function _main
1>pagrindinis.obj : error LNK2019: unresolved external symbol "void __cdecl Tvarkyti(class Klipas &,class Klipas &,int,int)" (?Tvarkyti@@YAXAAVKlipas@@0HH@Z) referenced in function _main
1>C:\Users\User\Desktop\re\LA2–11. Kepykla\LD3_111\Debug\LD3_111.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


It says that there are functions with names Trinti and Tvarkyti that have same argument lists, though thats nto this case. Am i missing something here??
It says that there are functions with names Trinti and Tvarkyti that have same argument lists, though thats nto this case. Am i missing something here??


Yes. You're missing something. That's not what it says at all. It says there is an uresolved exrernal symbol (a function the linker can't find) with the prototype void Trinti(Klipas) that is referenced called in pagrindinis.cpp.

The second error says there is an unresolved external symbol with the prototype void Tvarkyti(Klipas& Klipas&, int, int) which is called from main.


These declarations, are taken from pagrindinis.cpp:
1
2
void Tvarkyti(Klipas & K, Klipas & S, int rezX, int rezY);
void Trinti(Klipas K);


Notice that they match the prototypes for the unresolved externals - ie. you told the compiler you were going to define those functions. However, in pagrindinis.cpp we see that you actually defined the functions in a different way:

1
2
3
4
 void Tvarkyti(Klipas & K, Klipas & S, int & rezX, int & rezY)
{
    int n=0;
    // ... 


and

1
2
3
4
void Trinti(Klipas & K)
{
    int i=0;
    // ... 


You will notice that the parameter types for these functions do not match the parameter types for the declarations that occurred earlier in the code, and when the linker is looking for those functions, it's not going to find these functions.

The solution: Make sure the declarations match the definitions.


Last edited on
Wow thank you alot, ;) i am surprised how dumb of mistake that was xD
Topic archived. No new replies allowed.