Hello, i got in trouble once again, this time in excersise 14-4 in Accelerated C++.
When i compile i get an error message that you probably know.

fatal error LNK1169: one or more multiply defined symbols found

Can anyone see what i am missing here? Edit: This is all in the .hpp file with the class that uses the functions.

template<class T>
T* clone(const T* tp)
{
	return tp->clone();
}

template<>
std::vector<char>* clone(const std::vector<char>* vp)
{
	return new std::vector<char>(*vp);
}

Recommended Answers

All 2 Replies

Can you show more code. It looks fine to me.

The template functions worked as they should.
What i found was causing the problem was that i had included a .hpp file with a template function in a .cpp file:

#ifndef GUARD_Str3_info
#define GUARD_Str3_info
class Str3 {               //Str3.hpp
public:
	template<class In> Str3(In b, In e): data(new vector<char>) {
		std::copy(b, e, std::back_inserter(*data));
#include "stdafx.h"
#include "Str3.hpp"
//...                       //Str3.cpp

Do you know why i can not do this? I use Visual C++ 2008.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.