Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy did NetBeans show incorrect auto-completion?
    primarykey
    data
    text
    <p>I had an exam yesterday for Programming I at the end of my first semester. It was pretty basic, except I made a really, really obscure mistake that I wanted to ask the more experienced people here about:</p> <p>I basically had a class Library that contained a vector that contains elements of Loan* which contains a Customer and Book class. Kind of like this:</p> <pre><code>class Library { vector&lt;Loan*&gt; loans_; }; class Loan { Customer *customer_; Book *book_; }; </code></pre> <p>I had a function which required going through all the initialized book objects and seeing which ones belonged to whom, like this:</p> <pre><code>Customer *getBorrower(Book *book) { vector&lt;Loan*&gt;::iterator iter; for( iter = loans_.begin(); iter != loans_.end(); ++iter ) { if( (*iter).getBook() == book ) return (*iter).getCustomer(); else continue; } return 0; } </code></pre> <p>This stumped me, because in the Netbeans 6.9 IDE the (*iter). showed me a list of all the methods of the Loan object. </p> <p>I was just about to quit the exam when I loaded up VC++08 and it asked me if I didn't want to use <code>-&gt;</code> instead. </p> <p><code>(*iter)-&gt;getBook();</code> worked to my chagrin.</p> <p>So my question is: why did the IDE allow me to use <code>.</code> and even spit out a list of the methods as well as for <code>-&gt;</code>? To my knowledge, it doesn't do this kind of madness anytime else. What exactly happened here? I'm not understanding what I tried to make the method do that gave me that weird netbeans error "Is not of type Loan*"</p> <p>Second question: This is a style question. I commented to the professor about this, but he didn't seem too agreeable. The exam guidelines also had us create a public </p> <p><code>vector&lt;Book*&gt;</code> and <code>vector&lt;Customer*&gt;</code>.</p> <p>We then accessed these from the main function to run our unit tests. I found this to be in extremely bad practise since a simple getter function would have provided us with what we needed without publicizing our information. Was I right to call this out as a bad design choice? </p> <p><strong>Error:</strong> </p> <p>Library.cpp:14: error: request for member <code>getCustomer' in</code>(&amp;iter)->__gnu_cxx::__normal_iterator&lt;_Iterator, _Container>::operator* with _Iterator = Loan**, _Container = std::vector >', which is of non-class type `Loan*'</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload