trouble with constructors

I thought I had these figured out, but I guess not. I have a constructor:

1
2
3
4
5
6
7
8
9
DemodIqImp::DemodIqImp(int32_t rv) 			// constructor w/ reset param
{
	for (int i = 0; i < IQ_IMP_NBR_CELLS; ++i)
	{
		impCompI.push_back(rv);
		impCompQ.push_back(rv);
	}
	impCompI.at(0).display();
}


The constructors for impCompI andimpCompQ look like this:

1
2
DemodIqImpCell::DemodIqImpCell(int32_t rv)    // default constructor
	: a(rv), b(rv), c(rv), d(rv), e(rv), f(rv), g(rv), h(rv) {}


The objects a, b, c and so on contain three ints that get set to the value of rv (this much has been verified).

To me, it all looks right, but when the display line executes above, it's clear that the rv assignment isn't in those objects. I KNOW they're in there at some point, because I've stepped through the constructor for a/b/c/etc. and seen the assignments work. So, somehow it must be how I'm performing the nested constructions, right?

Any help would be appreciated.
You have an auto conversion operator from int32_t to DemodIqImpCell

Is this autoconversion being called in the push_back, or something else?

I never use autoconversion since it is trouble, I make all constructors that take a single argument explicit.

try

1
2
impCompI.push_back(DemodIqImpCell(rv));
impCompQ.push_back(DemodIqImpCell(rv));


to guarantee the correct conversion is being called.
What is an auto conversion operator?

I thought that by passing rv, it would simply pass that parameter through to the constructors of the subordinate classes. No?
Well, from the description I am assuming that impCompI and impCompQ are vectors of DemodIqImpCell ?

so when you push back the rv variable it has to be converted from int32_t to DemodIqImpCell ?

The constructor for DemodIqImpCell converts from int32_t to DemodIqImpCell without having to be called explicitly.
I've called that autoconversion.

I once had a bunch of math classes and wrote conversion operators like this wherever possible. After a lot of ambiguities arising and conversions I was not expecting, I don't do this any more.

Yes, your assumption is 100% correct.

Ohhhhhhhhhh, I think I get it now. So, the parameter to the push_back() is supposed to be an object of that vector. OK...duh. So, your technique will call the constructor for that object, and pass it the rv as an argument?
Yes, I've basically called the DemodIqImpCell constructor explicitly and pushed the resulting object straight onto the vector.

This is really just to take out any ambiguity.
I like it. A lot.

Thanks for the help.
Topic archived. No new replies allowed.