cout << "text text " << obj.method1() << " more text " << endl;
And would you explain why you find this ironic?
| [reply] [d/l] |
Presumably, he/she finds it ironic beacuse
cout << "text text " << obj.method1() << " more text " << end1;
is like using string concatenation in Perl. The root node says to use printf sometimes. printf is a C function, yet it would not be the preferred way of doing things in C.
So to prefer printf in Perl when something like the above (preferred) C snippet exists, is ironic. | [reply] [d/l] [select] |
printf is a C function, yet it would not be the preferred way of doing things in C.
That's half right - printf is a C function, but it is not preferred in C++. It is preferred in C, of course.
The reason why printf is not the best way in C++ is that the compiler cannot check the variable types. If you use "%s" to print a string, and then use an integer variable instead, the program crashes at run time. With perl it would just convert the integer into a string and not crash, and with C++ style I/O, it would print the integer as a string. Also, printf cannot be extended to print objects, it is only able to print a few built in types.
| [reply] |
#include <iostream.h>
class aclass {
public:
int first_perfect_number(void);
};
int aclass::first_perfect_number(void) {
return 6;
}
int main() {
aclass * ap = new aclass();
cout << "first perfect number is: " << ap->first_perfect_number()
+<< endl;
}
| [reply] [d/l] |
Right, but why on earth would you assume a pointer to an object in this case? The original bit wasn't talking about a reference to a perl object, so I assumed it was a typo. Just because the syntax passes the compiler doesn't mean it is what he meant. :)
| [reply] |