nexilion
Slavan
- Učlanjen(a)
- 14.08.2007
- Poruke
- 403
- Poena
- 319
Kod:
//student.h
class Student {
char* ime; // Ime studenta.
long ind; // Broj indeksa
int* ocene; // Niz ocena.
int kap, brOc; // Kapacitet niza i broj ocena.
Student (const Student&) {} // Ne sme da se kopira.
void operator= (const Student&) {} // Ne sme da se dodeljuje.
public:
Student (char* iime, long iind, int kkap=40);
Student promeniIme(const char* iime);
...
Kod:
//student.cpp
#include "student.h"
#include <cstring>
#include <cstdlib>
using namespace std;
Student::Student (char* iime, long iind, int kkap) {
ime = new char [strlen(iime)+1];
strcpy (ime, iime);
ind = iind;
ocene = new int [kap = kkap];
brOc = 0;
}
Student Student::promeniIme(const char *iime)
{
delete [] ime;
ime = new char[strlen(iime)+1]; //+1 ostavljamo mesta za /0
strcpy(ime, iime);
return *this;
}
...
Pri kompajliranju jedna greska: "1>studentt.obj : error LNK2019: unresolved external symbol "public: __thiscall Student::Student(char const *,long,int)" (??0Student@@QAE@PBDJH@Z) referenced in function _main
1>E:\Projekti\C++ Projekti\zad3.6\Debug\zad3.6.exe : fatal error LNK1120: 1 unresolved externals"
Kada stavim da bude: Student (const char* iime, long iind, int kkap=40); i naravno u cppu isto, onda radi bez problema. Dok funkcija promeniIme, radi i sa i bez const.
Zasto tako, sta je problem? I koja je razlika izmedju [znam da const pod a) kaze da necemo menjati parametare, a const u b)?]:
a) Funkcija(const param1, const param2){};
b) Funkcija(param1, param2) const {};