[Spit Groove] why I hate C + +

Source: Internet
Author: User

Recently in change currennt code, I wipe wipe, really can't endure

The most disgusting part of C + + is the pointer reference and object-oriented mixing!! TMD various mismatches

Example:

Template <typename tdevice>void trainablelayer<tdevice>::vectorxvector (real_vector* Destmatrix, Real_ vector* Srcvect1, real_vector* srcvect2) {int vect1size=srcvect1->size (); int vect2size=srcvect2->size (); for ( int row=0;row<vect1size;++row) {for (int col=0;col<vect2size;++col) {//real_t Value=srcvect1[row]*srcvect2[col ];?}}}

Code content don't mind, just say this real_vector, is an object, need to pass with the pointer

But this object is the thrust library implementation, want to access the elements in the Real_vector, only the overloaded [] can be used, that is real_vector[i] so ...

I rub, then here I how to use Ah!! Suppose Real_vector's pointer is P:

*p->[] is not allowed at the grammatical level. *p->get (i) is not implemented. P[i] Access to the content is not the vector I want to the first element of the ...

This is the result of giving the people too much flexibility, and finally it is this way of passing each other!

If overloading is not allowed, real_vector you honestly give me a get function, I can use it here!

---------------

All right...... I'm out, check it out, I need to dereference it before I can use the overload.

(*p) I

But it also reflects the C + + syntax is too flexible ~ really feel that learning this rule usage is a waste of time ...

Reference

http://www.cplusplus.com/forum/beginner/28033/

[Spit Groove] why I hate C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.