console.cpp:

#include <iostream>
#include <string>
#include <vector>
using namespace std;


template <typename T>
T
#ifndef _DEBUG
	&
#endif
val(const T& x);


class A
{
private:
	
public:
	void f();
};

void A::f()
{
	val(1);// deleting val solves the problem
}

int main()
{
	new A;
	cin.get();
}

general.cpp:

template <typename T>
T
#ifndef _DEBUG
	&
#endif
val(const T& x)
{
	return x;
}

the error:

Error 2 fatal error LNK1120: 1 unresolved externals G:\Important Files\My Documents\Visual Studio 2008\Projects\tack\Debug\tack.exe

I don't understand why my program has errors!?

I'm deducing templates cannot have external linkage! is that correct?

Near the end of that FAQ was a link to another one:

  1. A template is not a class or a function. A template is a "pattern" that the compiler uses to generate a family of classes or functions.

(More at the link.)

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.