I have a base class with a pure virtual function, and a derived class that implements it. When I try to call this function from the sub class object, I get a message:
Request for member 'stdOutAttrib' in rect, which is of non class type Rectangle()
Now Rectangle is indeed a class, so I don't know why it thinks it isn't. Also not sure why it has it as Rectangle() with the parentheses. Virtual functions are new to me, so bare with me.
std::string foo ; // foo is a default constructed std::string
std::string bar() ; // declare bar
// bar is a function taking no parameters and returning a std::string
I thought you did it first way (without parentheses) if there is no user- defined default constructor, and the second way if there is a user-defined default constructor?
> I thought you did it first way (without parentheses) if there is no user- defined default constructor,
> and the second way if there is a user-defined default constructor?
No.
> I don't really see the difference here
Try compiling this:
1 2 3 4 5 6 7 8 9 10 11 12 13
struct A { A() { /* default constructor */ } A(int) { /* constructor with arg */ } } ;
int main()
{
A one ; // one: default-constructed A (definition)
A* pa = &one ; // fine.
A two(23) ; // two: object of type A initialized with 23 (definition)
pa = &two ; // also fine
A three() ; // three: function returning an A and taking no args (declaration)
pa = &three ; // *** error: can't convert from pointer to function to pointer to A
}
If uniform initialization does catch on, the overwhelming beneficiaries would be students who are starting out to learn C++; it makes C++ programming simpler and more intuitive.
Though I doubt that it will catch on. The fundamental problem with C++ is its teachers - in schools, on the web, everywhere. Fourteen years after std::vector<> and std::string, students of C++ are still not learning programming. Instead, right from day two, they are being overwhelmed by the intricacies C-style arrays and dynamic memory management.