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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:16:38+00:00 2026-05-26T03:16:38+00:00

I have the following code, which is vital to understand a class I’m working

  • 0

I have the following code, which is vital to understand a class I’m working on translating from visual c++ to c#

typedef Rect<double, 2> Rect2;

I simply can’t understand what does it mean. I have come to understand that vc++ uses ‘stl’ or ‘std’ and a ‘vector’ class, which is similar to c# list or arraylist, but the syntax up completely eludes me.

By the way, Rect definition is written like this

template<class Real, int Dim>
class Rect {

Rect is a class in one of the vc++ project files, but I can’t understand what’s the point of this typedef. It’s 200+ lines so here’s the declaration start

template<class Real, int Dim>
class Rect {
public:

typedef Vector<Real, Dim> Vec;
typedef Rect<Real, Dim> Self;
typedef _RectPrivate::RectOp<Dim> RO;

Rect() : empty(true) {}
Rect(const Vec &vec) : empty(false), lo(vec), hi(vec) {}
Rect(const Vec &inLo, const Vec &inHi) : lo(inLo), hi(inHi) { markEmpty(); }
Rect(const Rect &inRect) : empty(inRect.empty), lo(inRect.lo), hi(inRect.hi) {}
template<class R> Rect(const Rect<R, Dim> &inRect) : empty(inRect.empty), lo(inRect.lo), hi(inRect.hi) {}

Any help appreciated.

  • 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-26T03:16:38+00:00Added an answer on May 26, 2026 at 3:16 am

    Based on your comments to the other answer, the problem you’re facing is that you do not understand what C++ templates are. They are actually quite different from C# generics. They are conceptually similar, and syntactically similar, but their actual implementation is very different.

    The easiest way to think about a template in C++ is as a “search and replace” mechanism. When you see

    typedef Rect<double, 2> Rect2;
    

    That means go find the template class for Rect that takes two template arguments. Here it is:

    template<class Real, int Dim>
    class Rect {
    

    OK, so “double” corresponds to “class Real” and “2” corresponds to “int Dim”. Sure enough, double is a type and 2 is an int, so that works properly. Now go through the template class and replace all instances of “Real” with “double” and “Dim” with 2. The result is:

    typedef /* now we start replacing double for Real and 2 for Dim */ 
    class Rect {
    public:
    typedef Vector<double, double> Vec;
    typedef Rect<double, 2> Self;
    typedef _RectPrivate::RectOp<2> RO;
    Rect() : empty(true) {}
    Rect(const Vec &vec) : empty(false), lo(vec), hi(vec) {}
    ...
    } Rect2;
    

    Notice that the result of search-and-replace on the template itself both defines and uses more templates, which have to themselves be search-and-replaced to construct them. We’d do a search-and-replace on the Vector template, and so on.

    The “typedef” just means “when I say Rect2 I mean Rect<double, 2>“. The same way in C# you can say

    using MyStringList = System.Collections.Generic.List<string>;
    

    There are many differences between C# generics and C++ templates. The obvious difference here is that C# generics can only be parameterized with types, never with values as is done in this template. Another difference is that C++ templates are fully constructed at compile time, and need only be legally constructable with the actual arguments given in the program. Whereas C# generics must be constructable with any arguments that meet the stated constraints, and the new code generation does not happen until runtime.

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

Sidebar

Related Questions

I have the following code which is used to Push and Pend from a
I have the following code which works fine to format text from an SQL
I have the following code which does nothing but reading some values from a
i have following code in which, i am fetching the data from the sqlite
I have the following code which adds a toolbar icon gtk-info (from stock) to
I have the following code which is executed from the command line: import cgi,time,os,json,sys,zipfile,urllib2
I have following code which on save from the admin area creates a duplicate
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which works just fine when the method is POST,

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.