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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:35:22+00:00 2026-05-14T03:35:22+00:00

This is my template matrix class: template<typename T> class Matrix { public: …. Matrix<T>

  • 0

This is my template matrix class:

template<typename T>
class Matrix
{
public:
....
Matrix<T> operator / (const T &num);
}

However, in my Pixel class, I didn’t define the Pixel/Pixel operator at all!

Why in this case, the compiler still compiles?

Pixel class

#ifndef MYRGB_H
#define MYRGB_H

#include <iostream>
using namespace std;

class Pixel
{
public:
    // Constructors
    Pixel();
    Pixel(const int r, const int g, const int b);
    Pixel(const Pixel &value);
    ~Pixel();

    // Assignment operator
    const Pixel& operator = (const Pixel &value);

    // Logical operator
    bool operator == (const Pixel &value);
    bool operator != (const Pixel &value);

    // Calculation operators
    Pixel operator + (const Pixel &value);
    Pixel operator - (const Pixel &value);
    Pixel operator * (const Pixel &value);
    Pixel operator * (const int &num);
    Pixel operator / (const int &num);

    // IO-stream operators
    friend istream &operator >> (istream& input, Pixel &value);
    friend ostream &operator << (ostream& output, const Pixel &value);

private:
    int red;
    int green;
    int blue;
};

#endif
  • 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-14T03:35:22+00:00Added an answer on May 14, 2026 at 3:35 am

    C++ templates are instantiated at the point you use them, and this happens for the Matrix<T>::operator/(const T&), too. This means the compiler will allow Matrix<Pixel>, unless you ever invoke the division operator.

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

Sidebar

Related Questions

I am writing matrix classes. Take a look at this definition: template <typename T,
template <typename T> class Table { public: Table(); Table(int m, int n); Table(int m,
We have two classes: template<typename T, typename Size, typename Stack, typename Sparse> class Matrix
Basically, I have a matrix class like this (with a lot of operator overloads
I have code like this: template <typename T, typename U> struct MyStruct { T
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Suppose I have code like this: template<class T, T initial_t> class Bar { //
In C++0x I would like to write a function like this: template <typename... Types>
In visual C++, I can do things like this: template <class T> class A{
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type

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.