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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:28:02+00:00 2026-06-12T16:28:02+00:00

I have two classes Triangle and ALine and I want to assign new ALine

  • 0

I have two classes Triangle and ALine and I want to assign new ALine instances to properties of Triangle in its constructor.
But I am getting this error

Undefined symbols for architecture x86_64:
  "ALine::ALine()", referenced from:
      Triangle::Triangle(triangle) in Triangle.o
ld: symbol(s) not found for architecture x86_64

Below is code I wrote:

ALine.cpp

#include "Geometry.h"
#include "ALine.h"



ALine::ALine(point a, point b)
{       
        double tmpy = a.y - b.y;
        double tmpx = a.x - b.x;
        double tmpk;
        if(equals(tmpy, 0))
        {
            tmpk = 0;
        }
        else
        {
            tmpk = tmpx/tmpy;
        }
        double tmpq = a.y - tmpk*a.x;
        if(equals(tmpx, 0))
        {
            if(equals(a.x, 0))
            {
                if(equals(b.x, 0)) tmpk = 0;
                else tmpk = (b.y-tmpq)/b.x;
            }
            else
            {
                tmpk = (a.y-tmpq)/a.x;
            }
        }
     

    
        a = a;
        b = b;
        k = tmpk;
        q = tmpq;
    
};

ALine.h

class ALine{
    
private:
    double k;
    double q;
    point a;
    point b;
    
    double length;
    
    void calculateLength();
    
public:
    
    ALine(point a, point b);
    ALine();
    
    
    
    point getK();
    point getQ();
    
    
    static bool areinline(point a, point b, point c);
    
    
};

Triangle.cpp

#include "Triangle.h"
#include "Geometry.h"
#include "ALine.h"


    


    Triangle::Triangle(triangle t)
    {
        triangle itself = t;
        a = *new ALine(itself.a, itself.b);
        b = *new ALine(itself.b, itself.a);
        c = *new ALine(itself.c, itself.a);
    };

Note, the classes are not complete, I pasted here only relevant code to my problem (if not, I can add more).

  • 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-12T16:28:03+00:00Added an answer on June 12, 2026 at 4:28 pm

    You’re declaring a default constructor but not defining one.

    // in ALine.h
    class ALine
    {
    private:
        void calculateLength(); // this is a declaration
    public:
        ALine(point a, point b); // this is another
        ALine(); // this is a declaration as well
    
    ...
    
    // in ALine.cpp
    ALine::ALine(point a, point b) // this is a definition
    {
        double tmpy = a.y - b.y;
        double tmpx = a.x - b.x;
        double tmpk;
        ...
    

    You’re telling the compiler that the function exists, so it’s letting you use it. This is legal. However, when the linker tries to process the compiled code, it looks for ALine::ALine() and can’t find it, because you never said what it was.

    Add to your ALine.cpp something like the following:

    ALine::ALine()
    {
    }
    

    That being said

    You are not using dynamic allocation correctly. As it currently is, you allocate a new ALine on the heap, copy it into an ALine on the stack, and then discard the address of the heap ALine (not once but 3 times). This is a memory leak, the ALines never go away and as long as your program is running, they will always be there.

    You would be much better off changing Triangle::Triangle(triangle other) to the following:

    Triangle::Triangle(const triangle& t) : a(t.a, t.b), b(t.b, t.c), c(t.c, t.a) {}
    

    This uses the syntax of Class::Class(args ...) : member(...), member2(...), ... { /* body */ } to initialize the members of a class in a constructor. One benefit of this is that their default constructors will not be called, as they would (implicitly) in your code.

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

Sidebar

Related Questions

I have two classes Order and Items I want a method like this class
I have two classes in a many-to-many relationship, but only one of them have
I have two classes: public class Article { private ISet<IdentNumber> identNumbers = new HashedSet<IdentNumber>();
I have two classes, and want to include a static instance of one class
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes, but don't what kind of relation i should use. I
I have two classes, A & B. B is inheriting from A, I want
I have two classes Person and Passport. Passport has foreignkey = personid. This is
I have two classes, one depends on another. It is implemented like this: class
I have two classes (MVC view model) which inherits from one abstract base class.

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.