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 3351590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:55:38+00:00 2026-05-18T01:55:38+00:00

when i was trying to seperate the declaration and implementation of a non-member overloaded

  • 0

when i was trying to seperate the declaration and implementation of a non-member overloaded operator, i got a LNK2001 error in VC2010, my code was like this:

-foo.h-

class A
{
public:
    A(float x);
    float x;
};
A operator +(const A&, const A&);

-foo.cpp-

A::A(float x)
{
    this->x = x;
}

A operator +(const A& lh, const A& rh)
{
    return A(lh.x + rh.x);
}

so once i use the ‘+’ operation, the error pumps out, but if i remove the declaration in the header file, there are no LNK2001 errors.. i cannot figure out why..

  • 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-18T01:55:38+00:00Added an answer on May 18, 2026 at 1:55 am

    I suspect you have the definition in a different namespace than the declaration. ADL is finding the declaration (since it’s in the same namespace as the class), and then you get an unresolved external error during link.

    e.g.

    -foo.h-

    namespace aspace
    {
      class A
      {
      public:
          A(float x);
          float x;
      };
      A operator +(const A&, const A&);
    }
    

    -foo.cpp-

    #include "foo.h"
    using namespace aspace;
    
    A::A(float x)
    {
        this->x = x;
    }
    
    A operator +(const A& lh, const A& rh)
    {
        return A(lh.x + rh.x);
    }
    

    Will give the error you describe. The solution is to put the operator+ definition in the correct namespace:

    namespace aspace
    {
      A operator +(const A& lh, const A& rh)
      {
          return A(lh.x + rh.x);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying out Code First. I've two seperate contexts using the same database. My
I'm not the best at this jquery stuff. But I'm trying to seperate the
I'm trying to build two seperate dictionaries with a file thats arranged in this
I am trying to seperate a field into two by finding the values that
I'm trying to add 2 seperate JLabels to 2 seperate JPanels, all within one
I am trying to print an int[] array from a seperate method in the
I trying to set separate style for particular widgets, like for one button with
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I am trying to seperate values in an array so i can pass them
I'm trying to display both the longitude and latitude in seperate textviews after the

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.