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

The Archive Base Latest Questions

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

This week I started to upgrade my knowledge from C to C++, I would

  • 0

This week I started to upgrade my knowledge from C to C++, I would like to overload some operators

I have a class called Matrix

#include "lcomatrix.h"

inline Matrix::Matrix(unsigned rows, unsigned cols) :
        rows_(rows), cols_(cols)
{
        data_ = new double[rows * cols];
}

inline Matrix::~Matrix() {
    delete[] data_;
}

inline double& Matrix::operator()(unsigned row, unsigned col) {
    return data_[cols_ * row + col];
}

inline double Matrix::operator()(unsigned row, unsigned col) const {
    return data_[cols_ * row + col];
}

The content of lcomatrix.h is

#include <iostream>

class Matrix {
public:
    Matrix(unsigned rows, unsigned cols);
    double& operator()(unsigned row, unsigned col);
    double operator()(unsigned row, unsigned col) const;

    ~Matrix(); // Destructor        
    Matrix& operator=(Matrix const& m); // Assignment operator      

private:
    unsigned rows_, cols_;
    double* data_;
};

Main.cpp

#include "lcomatrix.h"
#include <iostream>


/*-
 * Application entry point.
 */
int main(void) {

    Matrix mx(12,12);

    //std::cout << mx << std::endl;

    return 0;
}

Make file:

CPPFLAGS=-I /path/lcomatrix/
EFLAGS=

all : main.o lcomatrix.o
    g++ $(EFLAGS) -o main.out  main.o lcomatrix.o 

main.o: lcomatrix.o
    g++ $(EFLAGS) $(CPPFLAGS) -c main.cpp

lcomatrix.o: 
    g++ $(EFLAGS) -c /home/robu/UbuntuOne/ChibiOS-RPi/lcomatrix/lcomatrix.cpp

clean:
    rm *.o main.out 

When I try to build I receive the following link error:

make all 
g++  -c /home/robu/UbuntuOne/ChibiOS-RPi/lcomatrix/lcomatrix.cpp
g++  -I /home/robu/UbuntuOne/ChibiOS-RPi/lcomatrix/ -c main.cpp
g++  -o main.out  main.o lcomatrix.o 
main.o: In function `main':
main.cpp:(.text+0x1b): undefined reference to `Matrix::Matrix(unsigned int, unsigned int)'
main.cpp:(.text+0x2c): undefined reference to `Matrix::~Matrix()'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

I guess this a really stupid error, but as a beginner I couldn’t figure out the solution.

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

    Your method definitions are all inline. In order to inline a function, the compiler needs to see its definition whenever it is compiling the code that uses it.

    Either put the function definitions somewhere they can be seen at the point of use – in the header, or in another file #included by Main.cpp – or don’t mark them as inline.

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

Sidebar

Related Questions

I have just started this week in exploring Android Open GL ES and related
I started using NHibernate this week (struggling). I have a small application with 3
I'm new to WinDbg and have started using it this week to diagnose memory
I've literally just started programming in assembly language this week and I'm having some
An applet developed outside our company just started failing for some users this week.
I've started this week to use Maven for some projects I'm working on and
I just started learning Flex this week, and I cannot get an image path
Started working on a new application this week that is running the latest rails
Sorry if my question seems dumb. I've started using Eclipse Ganymede 3.4 this week
This week I have figured out how to modify form elements in the location

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.