jo hallo also hier der code...
Alles anzeigen
da schmeisst der compiler folgenden fehler raus:
ändere ich folgendes:
void ShowVector(const vector<T>& v)
{
cout<<"max_size()=" << v.max_size();
cout<<"\tsize()="<<v.
zu:
void ShowVector(const vector<T>& v)
{
cout<<"max_size()=" << v.max_size();
cout<<"\tsize()="<<v.
bekomme ich folgenden fehler:
hmmmmm,.... wieso?? wie änder ich das ab???
also ich benutze MinGW Dev Studio...
thx for help
Quellcode
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Student
- {
- public:
- Student();
- Student(const string& name, const int age);
- Student(const Student& rhs);
- ~Student();
- void SetName(const string& name);
- string GetName() const;
- void SetAge(const int age);
- int GetAge() const;
- Student& operator=(const Student& rhs);
- private:
- string itsName;
- int itsAge;
- };
- Student::Student()
- : itsName("Neuer Schueler"),itsAge(16)
- {}
- Student::Student(const string& name, const int age)
- : itsName(name),itsAge(age)
- {}
- Student::Student(const Student& rhs)
- :itsName(rhs.GetName()),itsAge(rhs.GetAge())
- {}
- Student::~Student()
- {}
- void Student::SetName(const string& name)
- {
- itsName=name;
- }
- string Student::GetName() const
- {
- return itsName;
- }
- void Student::SetAge(const int age)
- {
- itsAge=age;
- }
- int Student::GetAge() const
- {
- return itsAge;
- }
- Student& Student::operator=(const Student& rhs)
- {
- itsName=rhs.GetName();
- itsAge=rhs.GetAge();
- return *this;
- }
- ostream& operator<<(ostream& os,const Student& rhs)
- {
- os<<rhs.GetName()<<" ist "<<rhs.GetAge()<<" Jahre alt";
- return os;
- }
- template<class T>
- void ShowVector(const vector<T>& v);
- typedef vector<Student> SchoolClass;
- int main()
- {
- Student Harry;
- Student Sally("Sally",15);
- Student Bill("Bill",17);
- Student Peter("Peter",16);
- SchoolClass EmptyClass;
- cout <<"Leere Klasse:\n";
- ShowVector(EmptyClass);
- SchoolClass GrowingClass(3);
- cout << "Wachsende Klasse(3):\n";
- ShowVector(GrowingClass);
- GrowingClass[0]=Harry;
- GrowingClass[1]=Sally;
- GrowingClass[2]=Bill;
- cout<<" WachsendeKlasse(3) nach Zuweisung von Schuelern:\n";
- ShowVector(GrowingClass);
- GrowingClass.push_back(Peter);
- cout<<"Wachsende KLasse nach Zuweisung des 4ten Schuelers\n:";
- ShowVector(GrowingClass);
- GrowingClass[0].SetName("Harry");
- GrowingClass[0].SetAge(18);
- cout<<"Wachsende Klasse nach eintragung des namens\n:";
- ShowVector(GrowingClass);
- return 0;
- }
- template<class T>
- void ShowVector(const vector<T>& v)
- {
- unsigned int i;
- cout<<"max_size()=" << v.max_size();
- cout<<"\tsize()="<<v.size();
- cout<<"\tcapacity()="<<v.capacity();
- cout<<"\t"<<(v.empty()? "leer":"nicht leer");
- cout<<"\n";
- for( i=0;i<v.size();++i)
- cout << v[i]<<"\n";
- cout<<endl;
- }
da schmeisst der compiler folgenden fehler raus:
Linking...
C:\...\testclass\Debug\testclass.o(.text$_ZNSt14__simple_allocI7StudentSt24__default_alloc_templateILb1ELi0EEE10deallocateEPS0_j+0x1d): In function `ZN7StudentC2Ev':
C:\...\testclass\testclass.cpp:26: undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned)'
C:\...\testclass\Debug\testclass.o(.text$_ZNSt14__simple_allocI7StudentSt24__default_alloc_templateILb1ELi0EEE8allocateEj+0x1d):C:\Dokumente und Einstellungen\Tutor\Desktop\svn\transistor_kennlinien\testclass\testclass.cpp:26: undefined reference to `std::__default_alloc_template<true, 0>::allocate(unsigned)'
testclass.exe - 2 error(s), 0 warning(s)
ändere ich folgendes:
void ShowVector(const vector<T>& v)
{
cout<<"max_size()=" << v.max_size();
cout<<"\tsize()="<<v.
zu:
void ShowVector(const vector<T>& v)
{
cout<<"max_size()=" << v.max_size();
cout<<"\tsize()="<<v.
bekomme ich folgenden fehler:
Compiling source file(s)...
testclass.cpp
testclass.cpp: In function `void ShowVector(const std::vector<T,
std::allocator<_CharT> >&) [with T = Student]':
testclass.cpp:86: instantiated from here
testclass.cpp:119: warning: comparison between signed and unsigned integer
expressions
testclass.exe - 1 error(s), 1 warning(s)
hmmmmm,.... wieso?? wie änder ich das ab???
also ich benutze MinGW Dev Studio...
thx for help
