Hey guys, I was wondering...
I always assumed that references were more or less constant "dereferenced" pointers.
With that in my mind I tried to do this:
#include <iostream>
#include <string>
using namespace std;
void outputIt(const string * const textz00rs){
cout << *textz00rs << endl;
}
int main(){
outputIt("window");
return 0;
}
But that'll give me the error: cannot convert `const char*' to `const std::string*' for argument `1' to `void outputIt(const std::string*)'
So I tried:
#include <iostream>
#include <string>
using namespace std;
void outputIt(const string &textz00rs){
cout << textz00rs << endl;
}
int main(){
outputIt("window");
return 0;
}
And it works as planned! Where's the true difference between these two pieces of code? The compiler knows just as much in both cases, right?
Thanks in advance,
Nick