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);
Re: Stupid question: typedef or #define can do this?
No, it's not possible.
Why would you want to?
Re: Stupid question: typedef or #define can do this?
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.
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);
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 '_')?
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.