Structs and assignment operator / constructor

In this example, how is it possible that a0 and a1 are not identical?

1
2
3
4
5
6
7
8
9
10
11
struct A{
	A(){/*allows declaration of non-pointer type w/o args; does not actually initialize the object*/};
	A(void* arg1){/*...*/};
	/*...*/
};

int main(int argc, char** argv){
	A a0;
	a0=A(somevalue);
	A a1(somevalue);
};
For all that's good and sacred, they should.
However that responsibility falls on the coder (if they actually need to code any of them)

Consider that in operator= the objects are already initialised and some optimizations may be made, by instance avoiding a reallocation.


> allows declaration of non-pointer type w/o args; does not actually initialize the object
¿ah?
Last edited on
What I meant was declare an A instead of a A*. "A a0;" wouldn't be valid if I only had the second constructor. The resulting object isn't actually usable as far as member functions returning meaningful values, not segfaulting, etc

For that matter, am I correct in assuming that operator. for reference types is as expensive as operator-> for pointers?
Last edited on
Topic archived. No new replies allowed.