Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unresolved External Reference Puzzle

36 views
Skip to first unread message

MikeCopeland

unread,
Sep 16, 2014, 12:15:50 PM9/16/14
to
I am getting an Unresolved External Symbol compiler error (in VS2013
Express) that I cannot understand. In a common .h file, I have the
following declaration:

template <class T>
string setwLeft(int width, T data); // format w/left & width
template <class T>
string setwRight(int width, T data); // format w/right & width

In its .cpp file, I have defined both functions:

template <class T>
string setwLeft(int width, T data) // format w/left & width
{
ostringstream oss;
oss << left << setw(width) << data;
return oss.str();
}
template <class T>
string setwRight(int width, T data) // format w/right & width
{
ostringstream oss;
oss << right << setw(width) << data;
return oss.str();
}

In my main .cpp files, I reference and use "setwLeft" frequently, but
references to "setwRight" produce the compiler error. What am I doing
wrong? TIA


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

Paavo Helde

unread,
Sep 16, 2014, 12:51:02 PM9/16/14
to
MikeCopeland <mrc...@cox.net> wrote in
news:MPG.2e820fefb...@news.eternal-september.org:

> I am getting an Unresolved External Symbol compiler error (in
> VS2013

This is a linker error, not a compiler error.

> Express) that I cannot understand. In a common .h file, I have the
> following declaration:
>
> template <class T>
[...]
> In its .cpp file, I have defined both functions:

See http://www.parashift.com/c++-faq/templates-defn-vs-decl.html

Cheers
Paavo

Scott Lurndal

unread,
Sep 16, 2014, 12:51:19 PM9/16/14
to
MikeCopeland <mrc...@cox.net> writes:
> I am getting an Unresolved External Symbol compiler error (in VS2013
>Express) that I cannot understand. In a common .h file, I have the
>following declaration:
>
>template <class T>
>string setwLeft(int width, T data); // format w/left & width
>template <class T>
>string setwRight(int width, T data); // format w/right & width
>
> In its .cpp file, I have defined both functions:
>
>template <class T>
>string setwLeft(int width, T data) // format w/left & width
>{
> ostringstream oss;
> oss << left << setw(width) << data;
> return oss.str();
>}
>template <class T>
>string setwRight(int width, T data) // format w/right & width
>{
> ostringstream oss;
> oss << right << setw(width) << data;
> return oss.str();
>}
>
> In my main .cpp files, I reference and use "setwLeft" frequently, but
>references to "setwRight" produce the compiler error. What am I doing
>wrong? TIA
>
>

http://www.parashift.com/c++-faq/separate-template-fn-defn-from-decl.html

0 new messages