Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 07.08.2009, 19:15   #1
TheWanderer
Пользователь Подтвердите свой е-майл
 
Регистрация: 01.10.2008
Сообщений: 82
По умолчанию Ссылка на неразрешенный внешний символ(error LNK2019)

Вот сама программа:
Код:
#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("New student"), 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() << " is " << rhs.GetAge() << " years old";
	return os;
}

template <class T>
void ShowVector(const vector<T> &y);

typedef vector<Student> SchoolClass;

int main()
{
	Student Harry;
	Student Sally("Sally", 15);
	Student Bill("Bill", 17);
	Student Peter("Peter", 16);

	SchoolClass EmptyClass;
	cout << "EmptyClass:\n";
	ShowVector(EmptyClass);

	SchoolClass GrowingClass(3);
	cout << "GrowingClass(3):\n";
	ShowVector(GrowingClass);

	GrowingClass[0] = Harry;
	GrowingClass[1] = Sally;
	GrowingClass[2] = Bill;
	cout << "GroeingClass(3) after assigning students:\n";
	ShowVector(GrowingClass);

	GrowingClass.push_back(Peter);
	cout << "GroeingClass() after added 4th student:\n";
	ShowVector(GrowingClass);

	GrowingClass[0].SetName("Harry");
	GrowingClass[0].SetAge(18);
	cout << "GrowingClass() after Set\n:";
	ShowVector(GrowingClass);

	return 0;
}

template <class T>
void ShowVextor(const vector<T> &v)
{
	cout << "max_size() = " << v.max_size();
	cout << "\tsize() = " << v.size();
	cout << "\tcapacity() = " << v.capacity();
	cout << "\t" << (v.empty()? "empty": "not empty");
	cout << "\n";

	for(int i = 0; i<v.size(); i++)
		cout << v[i] << "\n";

	cout << endl;
}
При компиляции появляется такая ошибка:
1>test.obj : error LNK2019: ссылка на неразрешенный внешний символ "void __cdecl ShowVector<class Student>(class std::vector<class Student,class std::allocator<class Student> > const &)" (??$ShowVector@VStudent@@@@YAXABV?$ vector@VStudent@@V?$allocator@VStud ent@@@std@@@std@@@Z) в функции _main

Что-то не пойму, почему эта ошибка выскакивает и как её исправить… может, кто ни будь, подскажет, что я сделал не правильно?
P.S: Пользуюсь Microsoft Visual C++ 2008 Express Edition.
TheWanderer вне форума Ответить с цитированием
Старый 07.08.2009, 19:35   #2
pu4koff
Старожил
 
Аватар для pu4koff
 
Регистрация: 22.05.2007
Сообщений: 9,065
По умолчанию

template <class T>
void ShowVector(const vector<T> &y);
и
template <class T>
void ShowVextor(const vector<T> &v)
Найдите одно отличие
pu4koff вне форума Ответить с цитированием
Старый 07.08.2009, 19:58   #3
TheWanderer
Пользователь Подтвердите свой е-майл
 
Регистрация: 01.10.2008
Сообщений: 82
По умолчанию

Цитата:
Сообщение от pu4koff Посмотреть сообщение
template <class T>
void ShowVector(const vector<T> &y);
и
template <class T>
void ShowVextor(const vector<T> &v)
Найдите одно отличие
нашёл
Спасибо за помощь)
TheWanderer вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Внешний и Внутренний IP Пепел Феникса Win Api 7 09.02.2010 15:38
Как прервать внешний цикл? AndreyF Общие вопросы Delphi 15 15.06.2009 17:46
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/main.exe : fatal error LNK11 prefak Win Api 0 19.04.2009 16:51
Внешний Ip Enemy Работа с сетью в Delphi 3 20.11.2007 01:00