|
|
Conversion to non-scalar type
Suppose I have a template class Vector<t> and I define a child
class Indices : public Vector<int> {
public:
Indices(const Vector<int> &v);
....
}
Now class StaticVector<int,n> has an operator Vector<int>() method.
Why do I get then messages such as "conversion from StaticVector<int,
2> to non-scalar type Indices requested"???
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
juanjose.garciaripoll (183)
|
3/3/2010 2:36:30 PM |
|
Juanjo wrote:
> Suppose I have a template class Vector<t> and I define a child
>
> class Indices : public Vector<int> {
> public:
> Indices(const Vector<int> &v);
> ...
> }
>
> Now class StaticVector<int,n> has an operator Vector<int>() method.
>
> Why do I get then messages such as "conversion from StaticVector<int,
> 2> to non-scalar type Indices requested"???
>
Because you are probably doing copy initialization ("=" form). Try
Indices i(staticvector);
If you use "= staticvector;" or if you try to pass it to a function
expecting Indices it might fail, because for it to work not only it needs to
convert from staticvector to Indices using Indices' constructor, but during
this initialization, a second conversion is needed from staticvecor to
Vector<int>. Two user defined conversions in one such single sequence is not
allowed.
Perhaps write a function "fromStaticVector" that converts a static to a
dynamic vector, and pass the result to Indices.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Johannes
|
3/4/2010 4:19:42 AM
|
|
|
1 Replies
793 Views
(page loaded in 0.061 seconds)
Similiar Articles: Conversion to non-scalar type - comp.lang.c++.moderatedSuppose I have a template class Vector and I define a child class Indices : public Vector { public: Indices(const Vector &v); .... } Now... How to do image-type conversion - comp.lang.java.guiConversion to non-scalar type - comp.lang.c++.moderated > > Why do I get then messages such as "conversion from StaticVector<int, > 2> to non-scalar type Indices requested ... Help Non Integer sampling rate conversion c code - comp ...... api.opengl And a conversion does take time, because an integer has an another binary ... You should have shown the C/C++ source code ... Conversion to non-scalar type ... non-searchable PDF, convert to TIFF, ocr back to searchable PDF ...Conversion to non-scalar type - comp.lang.c++.moderated... pain text to TeX - comp.lang.awk For this I wrote a awk script to convert double quotes to the correct type in ... Pass vector parameter into integration function? - comp.soft-sys ...Conversion to non-scalar type - comp.lang.c++.moderated... you use "= staticvector;" or if you try to pass it to a function ... that converts a static to a dynamic vector ... "Moderated" List??? - comp.lang.asm.x86Conversion to non-scalar type - comp.lang.c++.moderated Suppose I have a template class Vector and I define a child class Indices : public Vector { public: Indices(const ... Variations On Formats On Arithmetic Scalar Types - comp.lang.c++ ...Hi All, We all know that, more often than not, the formats of scalar types such as ... Additionally the x87 FPU supports load/store conversion of 18-digit (10-byte) packed ... Uninitialized variables, why do they equal their name? - comp.lang ...Conversion to non-scalar type - comp.lang.c++.moderated Whenever a value actually had to be known at compile-time ... Conversion to non-scalar type - comp.lang.c++ ... converting 64 bits to a DES Key - comp.lang.java.security ...Convert signed integer to a 16-bit hex number - comp.soft-sys ... convert 32-bit ... Variations On Formats On Arithmetic Scalar Types - comp.lang.c++ ... For example, if ... What is "plain old data" type (POD)? - comp.lang.c++.moderated ...Scalar types, POD-struct types, POD-union types (clause 9), arrays of ... 4: A POD-struct is an aggregate class that has no non-static data members of type pointer ... Conversion from ‘Foo*’ to non-scalar type ‘Foo’ requested ...You will get messages about conversion difficulties if what is on the left-hand side of an assignment equals sign is not the same as what is on the right-hand side. conversion from '...' to non-scalar type '...' requested - C / C++Yes, hate me... I believe your explanations, of course!!!! But sometimes you NEED to be nasty. I explain why I cannot use const... class classHolder 7/22/2012 6:38:02 AM
|
|
|
|
|
|
|
|
|