Cześć, mam problem ze skompilowaniem programu w Microsoft Visual Studio 2012, a mianowicie podczas kompilacji pojawiaja się błędy:
1>------ Build started: Project: Program1, Configuration: Debug Win32 ------
1> my_coord.cpp
1>my_interf.obj : error LNK2019: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class my_coord &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVmy_coord@@@Z) referenced in function "public: void __thiscall my_interf::find(void)" (?find@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class my_coord &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAVmy_coord@@@Z) referenced in function "public: void __thiscall my_interf::find(void)" (?find@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: __thiscall my_vect<class my_coord>::~my_vect<class my_coord>(void)" (??1?$my_vect@Vmy_coord@@@@QAE@XZ) referenced in function __unwindfunclet$??0my_interf@@QAE@I@Z$0
1>Program1.obj : error LNK2001: unresolved external symbol "public: __thiscall my_vect<class my_coord>::~my_vect<class my_coord>(void)" (??1?$my_vect@Vmy_coord@@@@QAE@XZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: void __thiscall my_vect<class my_coord>::init(unsigned int)" (?init@?$my_vect@Vmy_coord@@@@QAEXI@Z) referenced in function "public: __thiscall my_interf::my_interf(unsigned int)" (??0my_interf@@QAE@I@Z)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: class my_coord * __thiscall my_vect<class my_coord>::get_begin(void)" (?get_begin@?$my_vect@Vmy_coord@@@@QAEPAVmy_coord@@XZ) referenced in function "public: void __thiscall my_interf::find(void)" (?find@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: class my_coord * __thiscall my_vect<class my_coord>::get_end(void)" (?get_end@?$my_vect@Vmy_coord@@@@QAEPAVmy_coord@@XZ) referenced in function "public: void __thiscall my_interf::find(void)" (?find@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: void __thiscall my_vect<class my_coord>::disp(void)" (?disp@?$my_vect@Vmy_coord@@@@QAEXXZ) referenced in function "public: void __thiscall my_interf::disp(void)" (?disp@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: void __thiscall my_vect<class my_coord>::push(class my_coord const &)" (?push@?$my_vect@Vmy_coord@@@@QAEXABVmy_coord@@@Z) referenced in function "public: void __thiscall my_interf::push(void)" (?push@my_interf@@QAEXXZ)
1>my_interf.obj : error LNK2019: unresolved external symbol "public: class my_coord * __thiscall my_vect<class my_coord>::pop(void)" (?pop@?$my_vect@Vmy_coord@@@@QAEPAVmy_coord@@XZ) referenced in function "public: void __thiscall my_interf::pop(void)" (?pop@my_interf@@QAEXXZ)
1>Program1.obj : error LNK2019: unresolved external symbol "public: void __thiscall my_interf::finish(void)" (?finish@my_interf@@QAEXXZ) referenced in function _wmain
1>Program1.obj : error LNK2019: unresolved external symbol "public: void __thiscall my_interf::defaul(void)" (?defaul@my_interf@@QAEXXZ) referenced in function _wmain
1>C:\Users\Wojtek\Documents\Ćwiczenia\Ćwiczenie 1\Program1\Debug\Program1.exe : fatal error LNK1120: 11 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Dodam, że do tej pory nie spotkałem się z tego typu błędami, dlatego chicałbym Was prosić o pomoc.
Poniżej zamieszczam wszystkie pliki, jakie utworzyłem do projektu - jest ich sporo, ale w takich plikach miały być poszczegolne czeseci zadania.
my_coord.h
#include "my_mess.h"
#include <iostream>
using namespace std;
class my_coord
{
double *pcoord; //pcoord[0] -; pcoord[1] - y
my_mess msg;
public:
my_coord() { alloc(); pcoord[0] = pcoord[1] = 0; }
my_coord(double x, double y);
~my_coord();
bool operator==(const my_coord &ob);
bool operator !=(const my_coord &ob);
private:
void alloc();
friend istream & operator>>(istream & wejscie, my_coord & obj);
friend ostream & operator<<(ostream & wyjscie, my_coord & obj);
};
my_coord.cpp
#include "stdafx.h"
#include "my_coord.h"
#include <iostream>
using namespace std;
my_coord::my_coord(double x, double y)
{
alloc();
pcoord[0]=x;
pcoord[1]=y;
}
my_coord::~my_coord()
{
if(pcoord)
delete [] pcoord;
}
bool my_coord::operator==(const my_coord &ob)
{
if(pcoord[0] != ob.pcoord[0])
return false;
else if(pcoord[1]!=ob.pcoord[1])
return false;
return true;
}
bool my_coord::operator!=(const my_coord &ob)
{
if(pcoord[0]==ob.pcoord[0])
return false;
else if(pcoord[1]==ob.pcoord[1])
return false;
return true;
}
void my_coord::alloc()
{
pcoord=0;
try
{
pcoord= new double [2];
}
catch(bad_alloc)
{
msg.mess(my_mess::ERR_ALLOC_MEM);
}
}
my_interf.h
#define MAX_INTERF_CHAR 512
#include "my_vect.h"
#include "my_coord.h"
class my_interf
{
public:
enum MY_INTERF
{
MY_INTERF_PUSH,
MY_INTERF_POP,
MY_INTERF_DISP,
MY_INTERF_FIND,
MY_INTERF_FINISH,
MY_INTERF_TOT
};
private:
my_vect<my_coord> vect;
char str_interf[MY_INTERF_TOT][MAX_INTERF_CHAR]; //komunikaty, wyświetlane na monitorze
my_mess msg;
public:
bool run;
my_interf();
my_interf(size_t dim);
void menu();
void push();
void pop();
void disp();
void find();
void finish();
void defaul();
};
my_interf.cpp
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////my_interf.cpp
#include "stdafx.h"
#include "my_interf.h"
//#include <iostream>
//using namespace std;
my_interf::my_interf(size_t dim)
{
sprintf_s(str_interf[MY_INTERF_PUSH], MAX_INTERF_CHAR*sizeof(char), "%d - push", MY_INTERF_PUSH);
sprintf_s(str_interf[MY_INTERF_POP], MAX_INTERF_CHAR*sizeof(char), "%d - pop", MY_INTERF_POP);
sprintf_s(str_interf[MY_INTERF_DISP], MAX_INTERF_CHAR*sizeof(char), "%d - disp", MY_INTERF_DISP);
sprintf_s(str_interf[MY_INTERF_FIND], MAX_INTERF_CHAR*sizeof(char), "%d - find", MY_INTERF_FIND);
sprintf_s(str_interf[MY_INTERF_FINISH], MAX_INTERF_CHAR*sizeof(char), "%d - finish", MY_INTERF_FINISH);
vect.init(dim);
run = true;
}
void my_interf::menu()
{
int i;
for(i=0; i<MY_INTERF_TOT; i++)
{
cout << str_interf[i] << endl;
}
}
void my_interf::push()
{
my_coord ob(0,0);
cin >> ob;
vect.push(ob);
}
void my_interf::pop()
{
my_coord *ptr = NULL;
ptr = vect.pop();
if(ptr)
{
cout << *ptr;
}
else
{
msg.mess(my_mess::WARN_ARR_EMPT);
}
}
void my_interf::disp()
{
vect.disp();
}
void my_interf::find()
{
my_coord ob(0, 0);
my_coord *ptr = NULL;
cout << "input x, y - object for search\n";
cin >> ob;
ptr = vect.get_begin();
size_t dist;
while(ptr)
{
ptr = Find(ptr, vect.get_end(), ob);
if(ptr)
{
dist = ptr-vect.get_begin();
cout << "it = " << dist << " " << *ptr;
ptr++;
}
else
cout << "search end\n";
}
}
my_mess.h
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////my_mess.h
#ifndef INCLUDE_MY_HEADER_my_mess_h
#define INCLUDE_MY_HEADER_my_mess_h
#include <iostream>
using namespace std;
class my_mess
{
public:
enum MY_MESSAGE
{
ERR_ALLOC_MEM, //błąd alokacji pamięci
WARN_ARR_FULL, //tablica jest wypelniona (last > ndim)
WARN_ARR_EMPT, //tablica jest pusta (last = 0)
WARN_ARR_UNKN, //niepoprawny kod działania (interfejs)
TOT_NUMB //ogólna ilość komunikatów
};
static char *strtab[TOT_NUMB]; //tablica tekstowa komunikatów
public:
void mess(enum MY_MESSAGE ms); //Przy wywołani tej funkcji na ekran //pozostaje wyprowadzony komunikat. Jeśli to błąd, obliczenia trzeba //skończyć, jeśli nie – kontynuować. ms – składowa enumeration, która podaje //numer komunikatu
};
#endif
my_mess.cpp
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////my_mess.cpp
#include "stdafx.h"
#include "my_mess.h"
//#include <iostream>
//using namespace std;
char *my_mess::strtab[] =
{
"E memory alloc error", //ERR_ALLOC_MEM
"W array is full", //WARN_ARR_FULL
"W array is empty", //WARN_ARR_EMPT
"W niepoprawny kod operacji" //WARN_ARR_UNKN
};
void my_mess::mess(enum MY_MESSAGE ms)
{
if(strtab[ms][0] == 'E')
{
cout << "ERROR: " << &strtab[ms][1] << endl;
system("pause");
exit(1);
}
else if(strtab[ms][0] == 'W')
{
cout << "WARNING: " << &strtab[ms][1] << endl;
}
}
my_vect.h
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////my_vect.h
#ifndef INCLUDE_MY_HEADER_my_vect_h
#define INCLUDE_MY_HEADER_my_vect_h
#include "my_mess.h"
#include <fstream>
template <class T>
class my_vect
{
T *dat; //wskaznik do danych typu ogolnego
size_t ndim; //rozmiar tablicy, na ktory pozostala zaalokowana
size_t last; //wskazuje na pierwsza pusta pozycje w tablice
my_mess msg;
public:
my_vect(size_t dm); //konstruktor - alokuje pamiec dla tablicy typu T
//na dm elementow
my_vect() { dat = NULL; ndim = last = 0; }
~my_vect();
void init(size_t dm); //alokuje pamiec o dm elementow, jesli dat = NULL
T *get_begin(); //zwraca wskaźnik do początku tablicy dat
T *get_end(); //zwraca wskaźnik do dat[last]
void disp(); //wyswietla stan tablicy
void push(const T &ob); //dodaje element typu T do pierwszej wolnej
//pozycji w tablice
T *pop(); //zwraca wskaznik do ostatniego elementu tablicy
//i usuwa jego, lub NULL (tablica pusta)
T & operator [] (const size_t ind); //0 <= ind < last
void remove(size_t ind); //usuwa element tablicy o indeksie ind, kompresuje tablicu
private:
bool alloc(); //alocuje pamięć
};
template <class T, class K>
T *Find(const T *p_begin, const T *p_end, const K &key)
{
if(p_begin==NULL)
{
cout<<"Podany wskaznik do tablicy jest pusty"<<endl;
return NULL;
}
T *wsk=const_cast<T*>(p_begin);
while(*wsk != *p_end)
{
if(*wsk==key)
return wsk;
++wsk;
}
return NULL;
}
#endif
my_vect.cpp
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////my_vect.cpp
#include "stdafx.h"
#include "my_vect.h"
#include <iostream>
using namespace std;
template <class T>
my_vect<T>::my_vect(size_t dm)
{
dat=NULL;
last=0;
ndim=dm;
alloc();
}
template <class T>
my_vect<T>::~my_vect()
{
if(dat)
delete [] dat;
}
template <class T>
void my_vect<T>::init(size_t dm)
{
if(dat == NULL)
{
last=0;
ndim=dm;
alloc();
}
}
template <class T>
T *my_vect<T>::get_begin()
{
return dat;
}
template <class T>
T *my_vect<T>::get_end()
{
return dat+last;
}
template <class T>
void my_vect<T>::disp()
{
T *ptr=get_begin();
for(;ptr != get_end(); ptr++)
cout<<*ptr<<" ";
cout<<endl;
}
template <class T>
void my_vect<T>::push(const T &ob)
{
if(last>=ndim)
if(!realloc())
{
msg.mess(my_mess::ERR_ALLOC_MEM);
}
if(dat)
{
dat[last]=ob;
++last;
}
}
template <class T>
T *my_vect<T>::pop()
{
if(dat && last)
return &dat[--last];
else
return NULL;
}
template <class T>
T & my_vect<T>::operator[](const size_t ind)
{
if(dat && (ind>=0) && (ind<last))
return dat[ind];
}
template <class T>
bool my_vect<T>::alloc()
{
if(!dat)
{
try
{
dat= new T[ndim];
}
catch(bad_alloc)
{
msg.mess(my_mess::ERR_ALLOC_MEM);
}
}
return true;
}
Program1.cpp
// LAB 7 - Program1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "my_interf.h"
int _tmain(int argc, _TCHAR* argv[])
{
int op; //operacje
my_interf ifc(1000);
while(ifc.run)
{
ifc.menu();
cin >> op;
switch(op)
{
case my_interf::MY_INTERF_PUSH: //push
ifc.push();
break;
case my_interf::MY_INTERF_POP:
ifc.pop();
break;
case my_interf::MY_INTERF_DISP:
ifc.disp();
break;
case my_interf::MY_INTERF_FIND:
ifc.find();
break;
case my_interf::MY_INTERF_FINISH:
ifc.finish();
break;
default:
ifc.defaul();
};
}
system("pause");
return 0;
}