CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Location
    Cracow - Poland (Europe)
    Posts
    59

    Stupid question: typedef or #define can do this?

    Hi. Is this possible to do something like this:

    typedef matrix<double> double matrix;
    or:
    #define "double matrix" matrix<double>
    :-)))

    Why I ask? I simply like to write:

    double matrix A(4,4);
    or (let's say):
    float matrix A(4,4);
    (without _ beetwen "double" and "matrix" words)

    insteed of:
    matrix<double> A(4,4);
    matrix<float> A(4,4);
    Sorry for my poor English language skill.

  2. #2
    Join Date
    Jan 2005
    Posts
    24

    Re: Stupid question: typedef or #define can do this?

    No, it's not possible.

    Why would you want to?

  3. #3
    Join Date
    May 2004
    Location
    Cracow - Poland (Europe)
    Posts
    59

    Re: Stupid question: typedef or #define can do this?

    Simply: look nice.
    Sorry for my poor English language skill.

  4. #4
    Join Date
    Jan 2005
    Posts
    24

    Re: Stupid question: typedef or #define can do this?

    In any language you are better off learning to work with the way the language is, rather than trying to force the language to work in the way you want it to.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Stupid question: typedef or #define can do this?

    I'm not sure what matrix is, but of course you can typedef it. Here is a simple example with vector:
    Code:
    #include <vector>
    
    using namespace std;
    
    typedef vector<int> INTVECTOR;
    typedef INTVECTOR::iterator INTVECTOR_ITERATOR;
    
    int main()
    {
      INTVECTOR vc;
      INTVECTOR_ITERATOR vc_iterator;
    
      return 0;
    }
    So you can do this with your matrix:
    Code:
    typedef matrix<double> double_matrix;
    typedef matrix<float> float_matrix;
    
    double_matrix A(4,4);
    float_matrix B(5,5);
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Stupid question: typedef or #define can do this?

    Quote Originally Posted by Yansen
    Hi. Is this possible to do something like this:
    As being pointed out, it is not possible the way you are trying to do it. However, what is the deal to have two words instead of one (separated by a '_')?

  7. #7
    Join Date
    Mar 2004
    Location
    Temuco, CHILE
    Posts
    161

    Wink Re: Stupid question: typedef or #define can do this?

    Quote Originally Posted by Andreas Masur
    As being pointed out, it is not possible the way you are trying to do it. However, what is the deal to have two words instead of one (separated by a '_')?
    I don't understand it either... I've been incomortable with typedef's sometimes, but I've never had problems reducng two words to a one-word-with-a-'_'.

    My guess is that, like other cases one may see, a misunderstanding of the intentions of the class coder leads to the class user to request a feature "embedded" in C/C++.
    I've read some forums with questions on how to get "unsigned float"s and even on how to apply C++ keywords to user-defined types, such as the guy next door who wanted some BigInteger class to behave like unsigneds and thus requested to have "unsigned BigInteger". Swear to Spork I've seen that!

    Thes people want C++ to be "reconstructed" their way, thus implementing whatever they want; of course because of the amount of effort needed that should be impossible; instead they should adapt to the good things C++ comes with, and if a REAL change is needed, then by the ways of the Comittee (or by a good Boost implementation) it will be in order.
    You're not watching "24"?
    Well... you should.

    24
    Jack IS back...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured