Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:12:44+00:00 2026-05-30T23:12:44+00:00

I have a class Vector<T> , and am using a library that provides a

  • 0

I have a class Vector<T>, and am using a library that provides a class YAML::Node. I would like to overload operator>> for these two types.

I have added the following declaration to Vector‘s declaration:

friend void operator>>(YAML::Node const & node, Vector<T> & v);

I have also added the following implementation of the function:

template<typename T>
void operator>>(YAML::Node const & node, Vector<T> & v) {
    node[0] >> v.x;
    node[1] >> v.y;
    node[2] >> v.z;
}

Finally, I have added the following (attempt at) explicitly instantiating the template for T = num_t:

template
void operator>>(YAML::Node const & node, Vector<num_t> & v);

However, this results in the following linker error:

Error   9   error LNK2019: unresolved external symbol "void __cdecl operator>>(class YAML::Node const &,class Vector<double> &)" (??5@YAXAEBVNode@YAML@@AEAV?$Vector@N@@@Z) referenced in function "public: static class Scene __cdecl Scene::fromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?fromFile@Scene@@SA?AV1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

(num_t is a typedef for double)

However, if I add the following (non-template) implementation of the function, everything compiles fine:

void operator>>(YAML::Node const & node, Vector<num_t> & v) {
    node[0] >> v.x;
    node[1] >> v.y;
    node[2] >> v.z;
}

Why is the template version of the function not working?

Edit: Forgot to mention; the compiler is Visual Studio 11 Beta

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:12:45+00:00Added an answer on May 30, 2026 at 11:12 pm

    Declaring the function as a friend does not declare a function template; instead, each specialisation of the class template declares a non-template function, with its parameter types overloaded according to the template arguments. These will be chosen instead of the template you define; but they are not defined, hence the error.

    To fix it, you can either declare the function template before the class template (in which case the friend declaration will make that a friend, rather than declare a new function), or define the friend function inline, inside the class template, so that each specialisation of the class template defines the function as well as declaring it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have
I have a class that has a vector of another class objects as a
I have a class (foo) that contains a vector. If i try iterating over
Let's say I have a: std::vector<std::list<Node> > And let's say Node is: class Node
I am trying to sort a vector below using boost::phoenix library. The class Foo
I am writing a library that I would like to be portable. Thus, it
I'm using two 3rd party libraries, which both implement their own 2D vector class.
I have a class AudioDeviceManager that passes a std::vector by reference to an AudioAnalyzer
I have a handle-based class that I need to create a vector of. An
I have class A: public B { ...} vector<A*> v; I want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.