Click to See Complete Forum and Search --> : Stupid question: typedef or #define can do this?
Yansen
January 11th, 2005, 05:51 AM
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);
Mr Jack
January 11th, 2005, 06:19 AM
No, it's not possible.
Why would you want to?
Yansen
January 11th, 2005, 06:26 AM
Simply: look nice.
Mr Jack
January 11th, 2005, 07:31 AM
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.
cilu
January 11th, 2005, 10:44 AM
I'm not sure what matrix is, but of course you can typedef it. Here is a simple example with vector:
#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:
typedef matrix<double> double_matrix;
typedef matrix<float> float_matrix;
double_matrix A(4,4);
float_matrix B(5,5);
Andreas Masur
January 11th, 2005, 12:02 PM
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 '_')?
Luchin_plusplus
January 11th, 2005, 12:50 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.