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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:14:46+00:00 2026-05-27T12:14:46+00:00

struct Matrix(T, size_t row, size_t col){ alias row Row; alias col Col; auto opBinary(string

  • 0
struct Matrix(T, size_t row, size_t col){

  alias row Row;
  alias col Col;

  auto opBinary(string op, M)(in M m) const if(op == "*"){
    static assert(Col == M.Row, "Cannot Mix Matrices Of Different Sizes.");
    // whatever...
    return Matrix!(T, Row, M.Col)();
  }
}


void main(){


  Matrix!(double, 2, 3) m1 = Matrix!(double, 2, 3)();
  Matrix!(double, 3, 2) m2 = Matrix!(double, 3, 2)();
  Matrix!(double, 2, 2) m3 = m1 * m2;  // ERROR
// Error: cannot implicitly convert expression (m1.opBinary(m2)) of type Matrix!(double,row,col) to Matrix!(double,2,2)
}

Why the error and how can I solve this problem?

  • 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-27T12:14:47+00:00Added an answer on May 27, 2026 at 12:14 pm

    The problem is that, currently, templates are instantiated with their argument types, not their parameter types.

    If you changed your return statement to:

    return Matrix!(T, cast(int)Row, cast(int)M.Col)();
    

    It will compile, because it was instantiated with int, not size_t (which is uint or ulong).

    This is a long-standing bug and although he previously didn’t like it, Walter recently changed his mind supporting changing this to use the parameter types. Here is the pull request fixing this issue (it will be in the next DMD release), linking various related bugs.

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

Sidebar

Related Questions

//list.h file typedef struct _lnode{ struct _lnode *next; size_t row; size_t column; short data;
struct TimerEvent { event Event; timeval TimeOut; static void HandleTimer(int Fd, short Event, void
struct Group { Group(string _N, set <string> M_) {Name = N_; Member = M_}
struct Drink { public string Name { get; private set; } public int Popularity
I'm trying to create a matrix data structure in C. I have a struct
I have defined a Matrix module as follows: module Matrix = struct type 'a
I have a matrix struct: typedef struct Matrix { float m[16]; } Matrix; When
typedef struct Matrix { double * matrix; int sizex; int sizey; }Matrix; int nn
I have a bit of confusion regarding the matrix row/column order of the CATransform3D
I have the following code: template <typename M> struct Matrix { Matrix(int size);//(int x

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.