Not really a huge issue, but I’m wondering if IntelliSense is messed up when it comes to friend functions in classes?
I have a class that uses the overloaded operators for ostream and istream (<<, >>), and I have them flagged as friend functions inside my class. So theoretically they should have access to the class’s private members. The program compiles and runs fine, no errors – but as I’m continuing to write code, IntelliSense is constantly reporting that the member functions are inaccessible to the functions. It still compiles, but I’m wondering if this is a problem with IntelliSense or something on my end and I just happen to be getting lucky that’s it’s running at all?
friend std::ostream & operator <<(std::ostream &, const Rational &);
friend std::istream & operator >>(std::istream &, Rational &);
std::ostream & operator <<(std::ostream & outs, const Rational & source)
{
outs << source.itsNum << '/' << source.itsDen;
return outs;
}
std::istream & operator >>(std::istream & ins, Rational & target)
{
ins >> target.itsNum >> target.itsDen;
return ins;
}
There is nothing wrong with your code. My bet would be that IntelliSense messes up. Try deleting the IntelliSense database for your project to see if the error will go away (the IntelliSense database will rebuild itself after restart of the Visual Studio). The database should be located alongside your
.slnfile and (at least for Visual Studio 2008) has the extension.ncb.Other than that, some additional info. The IntelliSense feature for VisualStudio AFAIK is actually developed by a different company than Microsoft, so the compiler and IntelliSense may sometimes have different opinions on what is correct and what is not. Just saying. 🙂