struct bob {
int var;
bob() {
cout << "You've been initialized.";
}
};
If you try to declare an object like so: bob obj();
That doesn't call the constructor, and more importantly, that isn't even an object because you can't access obj.var.
Then what is obj()! And why is it like this!?
Note that it compiles. Why does it compile?
edit: Is it being treated as a function prototype.. ;-;? I just realized.. Sorry.. stupid me.
But since we're here,
how does vector 5 in <int> foo(5); get considered as std::vector<int, std::allocator<int>>?
Also another question: Can you change the operator precedence for overloaded operators in a class?
And can you make your own operator - for a class (suppose I want # to be an operator to raise to the power of)?
What I meant was since 5 is of type int, how was it considered as allocator. What would happen if there was an int constructor? But I guess allocator can be any type because of template and since there's no type specific constructors for vectors it would work fine. And if there were type specific constructors then they would be used over the allocator because the template would never be called (correct me if I'm wrong).
Cool I didn't realize you could use template as constructor parameter.
Okay so I can't overload operators or change the precedence. That sucks. :'(
Consider taking more time to read the documentation properly. You are right about not being able to change precedence.
I didn't get the hint.. is 'consider taking more time to read the documentation properly' referring to the statement 'Okay so I can't overload operators or change the precedence'?
Then can you be more specific.. do you mean to say that it's partially correct but not fully? Or what did you mean to say? I don't get it..
> how does std::vector<int> foo(5); get considered as std::vector<int, std::allocator<int> >?
Template: template < typename T, typename Allocator = std::allocator<T> > > class vector;
In std::vector<int> foo(5); the second template argument (for the allocator) is defaulted,
so the type of foo is std::vector< int, std::allocator<int> >