c++ declare variable by size of type instead of type -
Is there a way to define a variable in C ++ by specifying the size instead of size? Or is there any way to return type from a function?
template & lt; Typename T, int L & gt; Square vector {public: t * __vector; }; #ifdef USE_FLOAT typedef vector & lt; Float, 3 & gt; Vec3 #else typedef vector & lt; Double, 3 & gt; Vec3; #endif zero myFunc (vec3) {float a = vc 3. vector [0]; // AHHH But what if VC3 is a vector of doubles? // i type size can be obtained from int s = sizeof (vec3 [0]); // So can I just declare a variable by giving the size of the variable? }
Alternatively, is there any accessor function in class, which can return the template typename?
Any suggestion would be helpful. I know there are other ways around this issue, but I am particularly thinking that none of these two could be possible. (I have less hope for the second method.)
I think the first path is possible using zero pointer and mauloking ... but I want to avoid using the heap and just stick If possible, with stack.
Edit:
Just to clarify, I do not think that auto
will be helpful in my particular situation, even though I did not explain why it is more complete Code and tells me why I do not like it (definitely can be wrong) that auto
will not solve this issue.
I have another metric defined as well. / P>
template & lt; Typename T, int L & gt; Class Matrix {public: T * __matrix; }; #ifdef USE_FLOAT Typedef Matrix & lt; Float, 4 & gt; Mat4; #Allus TypedF Matrix & lt; Double, 4 & gt; Mat4; #endif
And my myfunc functions look like this:
cancel myFunc (vec3) {float one = vc 3.__ vector [0] ; // AHHH But what if VC3 is a vector of doubles? // i type size can be obtained from int s = sizeof (vec3 [0]); // So can I just declare a variable by giving the size of the variable? Matrix & lt; The same type ASVC3, 4 & gt; Mat (); }
I do not think I can understand that code with auto
but I would love to be wrong!
C ++ solution, as the code above is in C ++:
You can declare a publicly typed member in your vector category like this:
template cancel myFunc (vec3 vec) {// declare a Vec vec :: value_type a = vec .__ vector [0] be the same type of tie elements; There is an added benefit of fully trusting the vec3
API on how to implement vec3
without breaking your work can be done .
Comments
Post a Comment