warning: cannot pass objects of non-POD type
What does is a non-POD type? I get this error compiling the following code.
Code:
template<class BaseType, class X> |
Please post the exact error message you got.
|
/home/bobby/test/src/test.cpp:258: warning: cannot pass objects of non-POD type `class VectorND<int, int[4]>' through `...'; call will abort at runtime
That's the message in its entirety. I looked up what POD means. It means Plain Old Data. Apparently classes are not guaranteed to be passed evenly onto the stack or something. So, va_arg is not guaranteed to work hence the segmentation fault error. Is there any way around this? |
Pass a pointer; also try passing a reference. If the latter solution works, use that one.
|
I have been reading on meta-programming. Is there any way to adjust the arguments using meta-programming?
|
Why so complicated? Have you tried the references?
|
Yes, references are instant death. Seems like I'm forced to use pointers which is inconsistent with the rest of the class design. For example, on initialization, I passed data to my vectors using this:
Code:
template<class BaseType, class X> Code:
int main() Code:
int main() |
Is there an upper bound to the number of arguments? If yes, you could just use default values (I don't know whether that is possible with non-POD types); if the caller passes too many arguments, your algorithm can simply ignore them.
However, in my opinion, this solution is much uglier than passing an array (respectively a std::vector). |
Alright, looks like I made the right move.
|
It has been a while since I last posted this question, but I did manage to solve the problem entirely. If you want the answer, read on. I'll be using sudo code since I don't want to spend a lot of time trying to simplify complex code. Basically, have the constructor set the vector to zero. Second, overload the assignment operator to take in a value (such as an integer to the first component) and then have the operator return an intializer object.
Code:
InitObj operator=(const int val) Code:
InitObj operator,(const int val) Vector<int, 3> v; //calls the vectors operator= and the uses the initializers operator, to initialize the rest v = 1, 2, 3; This is neet and compact. Initializing the vectors may be a little slower since the constructor can't be used directly, but this is a nice solution to a hard problem. |
All times are GMT -5. The time now is 08:33 AM. |