How to return a pointer to an object? : <p>I have created two classes one called Pair(as data members has a dynamically allocated array of chars for KEY and double for value) and the other Collection(which is a collection of Pairs, as data members it has a dynamically allocated array of pairs, and a int variable for the sizeOfPairs). The Collection class should have a method that should return a pointer to the first objects with the provided key, if such object does not exist returns NULL pointer. This is how far I got with that method, but I get an error(error: indirection requires pointer operand ('Pair' invalid)) for the 4th line. Is the way I am returning a pointer to an object correct?</p>

<pre><code>Pair *find(const char *key){
        for(int i = 0; i &lt; sizeOfPair; ++i){
        if(pair[i].getKey() == key){
            return *pair[i];
        }else{
            return NULL;
        }
    }
}
</code></pre>
