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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:07:06+00:00 2026-05-26T05:07:06+00:00

First of all, I know that one has to implement the definition in the

  • 0

First of all, I know that one has to implement the definition in the header files, and that’s what I generally did according to this thread

I have several files

// Image.h
namespace library
{
    namespace data
    {
        template<class Pixel, class SubPixel, int Layer>
        class Image 
        {
            public:
            Image(int width, int height, Pixel emptyFill);
            Image(int width, int height);
            ~Image();

            Pixel& operator() (int x, int y);
            const Pixel& operator() (int x, int y) const;
            SubPixel& operator() (int x, int y, int subpixel);
            const SubPixel& operator() (int x, int y, int subpixel) const;

            protected:
            int m_width;
            int m_height;

            Pixel* m_pixels;
            void init(Pixel emptyFill);
            bool checkBounds(int x, int y, int layer = 0) const;

            virtual SubPixel& pixelToSubpixel(Pixel& pixel, int layer) const = 0;
        };

        template<class Pixel, class SubPixel, int Layer>
        Image<Pixel, SubPixel, Layer>::Image(int width, int height)
        : m_width(width), m_height(height), m_pixels(new Pixel(width * height))
        {
            init(0);
        }

        template<class Pixel, class SubPixel, int Layer>
        Image<Pixel, SubPixel, Layer>::~Image()
        {
            delete m_pixels;
        }


        template<class Pixel, class SubPixel, int Layer>
        Pixel& Image<Pixel, SubPixel, Layer>::operator() (int x, int y)
        {
            // implementation ...
        }

        template<class Pixel, class SubPixel, int Layer>
        const Pixel& Image<Pixel, SubPixel, Layer>::operator() (int x, int y) const
        {
            // implementation ...
        }

        template<class Pixel, class SubPixel, int Layer>
        SubPixel& Image<Pixel, SubPixel, Layer>::operator() (int x, int y, int subpixel)
        {
            // implementation ...
        }

        template<class Pixel, class SubPixel, int Layer>
        const SubPixel& Image<Pixel, SubPixel, Layer>::operator() (int x, int y, int subpixel) const
        {
            // implementation ...
        }

        template<class Pixel, class SubPixel, int Layer>
        void Image<Pixel, SubPixel, Layer>::init(Pixel emptyFill)
        {
            // implementation ...
        }

        template<class Pixel, class SubPixel, int Layer>
        inline bool Image<Pixel, SubPixel, Layer>::checkBounds(int x, int y, int subpixel) const
        {
            // implementation
        }

    }



}


// DepthImage.h:
namespace library
{
    namespace data
    {
        template class Image<unsigned short, unsigned short, 1>;
        class DepthImage : public Image<unsigned short, unsigned short, 1>
        {
            public:
            DepthImage(int width, int heigth);
            DepthImage(int width, int heigth, unsigned short emptyfill);
            ~DepthImage();

            protected:

            virtual unsigned short& pixelToSubpixel(unsigned short& pixel, int layer) const;
            private:
            DepthImage();

        };

    }
}

The whole thing is compiled to a shared object library. This works fine.

As soon as I try to link an executable object against this .so-file, I receive:

library.so: undefined reference to `library::data::Image<unsigned short, unsigned short, 1>::Image(int, int, unsigned short)'
collect2: ld returned 1 exit status

I even thought to make a explicit template instanciation at DepthImage.h. As DepthImage is not a templated class (it’s just extending one), I don’t understand the problem.

Any idea??

Regards, Tobias

  • 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-26T05:07:07+00:00Added an answer on May 26, 2026 at 5:07 am

    You have not provided a definition for Image(int width, int height, Pixel emptyFill);, only for Image(int width, int height);

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

Sidebar

Related Questions

First of all: I do know that there are already many questions and answers
First of all, I know that UDP is not a reliable protocol but I
First of all I know similar questions has been asked here, I've checked but
First of all I don't know if this is the right approach. I want
First of all, this is the first time that I use Hibernate so my
Note first of all that this question is not tagged winforms or wpf or
I know that this question has been asked too many times, but I think
I know, that I am not the first one to try to use Cocoa
First of all i don't know whether the title is relevant or not (please
first of all i would like to say i know its probably an easy

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.