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

  • Home
  • SEARCH
  • 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 8279253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:16:18+00:00 2026-06-08T09:16:18+00:00

I posted this yesterday. People suggested that I should have Point.h and Point.cpp files

  • 0

I posted this yesterday. People suggested that I should have Point.h and Point.cpp files since I’m using template. I created separate files for my class Point, and I’m still receiving errors.

//Point.h
Point(T = 0, T = 0, string = "Deafault Point");
~Point();
T operator-(const Point<T> &);  

//Point.cpp
template < typename T >
Point<T>::Point(T x,T y, string name)
:X(x), Y(y), Name(name)
{
}

template < typename T >
Point<T>::~Point()
{
}

template < typename T>
T Point<T>::operator-(const Point<T> &rhs)
{
cout << "\nThe distance between " << getName() << " and " 
<< rhs.getName() << " = ";

return sqrt(pow(rhs.getX() - getX(), 2) + pow(rhs.getY() - getY(), 2));;
}

//main.cpp
#include <iostream>
#include <math.h>
#include "Point.h"

using namespace std;

int main () {

Point<double> P1(3.0, 4.1, "Point 1");
cout << P1;

Point<double> P2(6.4, 2.9, "Point 2");
cout << P2;

cout << (P2 - P1);
return EXIT_SUCCESS;
}

This is what I got:

Undefined symbols:
"std::basic_ostream<char, std::char_traits<char> >& operator<< <double (std::basic_ostream<char,  std::char_traits<char> >&, Point<double> const&)", referenced from:
  _main in main.o
  _main in main.o
"Point<double>::operator-(Point<double> const&)", referenced from:
  _main in main.o
"Point<double>::Point(double, double, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
  _main in main.o
  _main in main.o
"Point<double>::~Point()", referenced from:
  _main in main.o
  _main in main.o
  _main in main.o
  _main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Any help is appreciated…

  • 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-06-08T09:16:20+00:00Added an answer on June 8, 2026 at 9:16 am

    People suggested that I should have Point.h and Point.cpp files since I’m using template

    Whoever suggested this is dead wrong. Implementations for templates must be visible.

    You can separate the implementation to a file, but you need to include it as well afterwards. The only situation when you can hide the implementation of a template is when you know the specializations and declare them beforehand. (this doesn’t apply here)

    You need a single file for the template:

    //Point.h
    
    template <typename T>
    struct Point
    {
       Point(T = 0, T = 0, string = "Deafault Point");
       ~Point();
       T operator-(const Point<T> &);  
    };
    
    template < typename T >
    Point<T>::Point(T x,T y, string name)
    :X(x), Y(y), Name(name)
    {
    }
    
    template < typename T >
    Point<T>::~Point()
    {
    }
    
    template < typename T>
    T Point<T>::operator-(const Point<T> &rhs)
    {
    cout << "\nThe distance between " << getName() << " and " 
    << rhs.getName() << " = ";
    
    return sqrt(pow(rhs.getX() - getX(), 2) + pow(rhs.getY() - getY(), 2));;
    }
    

    Also, the naked string in the header suggests you have a using namespace std; in the header as well. That’s bad practice, remove the using directive and qualify the name std::string.

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

Sidebar

Related Questions

I have posted this yesterday, I didn't get the the answers that could solve
I posted this question yesterday and the answer I go mentioned that I should
Similar to the question I posted yesterday , I have this problem that I
Yesterday I posted this question regarding using lambdas inside of a Join() method to
I posted this yesterday on SO, and I received an answer that works great,
I have posted this problem yesterday..but unfortunately, no one has given me the solution
Yesterday I posted this question about protecting files: Protecting the app sandbox As mentioned,
This is a followup to a question I posted yesterday. I thought everything was
Yesterday, I posted a question on some tips doing this Remote Client-Server Application in
I posted a question yesterday which was answered, sadly though I now have a

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.