mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 14:56:54 +02:00
Minor C++ fixes
This commit is contained in:
@@ -150,7 +150,7 @@ int main()
|
|||||||
|
|
||||||
#include <iostream> // Include for I/O streams
|
#include <iostream> // Include for I/O streams
|
||||||
|
|
||||||
using namespace std;
|
using namespace std; // Streams are in the std namespace (standard library)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -175,7 +175,7 @@ int main()
|
|||||||
// Strings in C++ are objects and have many member functions
|
// Strings in C++ are objects and have many member functions
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std; // Strings are in the namespace std (standard library)
|
using namespace std; // Strings are also in the namespace std (standard library)
|
||||||
|
|
||||||
string myString = "Hello";
|
string myString = "Hello";
|
||||||
string myOtherString = " World";
|
string myOtherString = " World";
|
||||||
@@ -210,7 +210,7 @@ string bar = "I am bar";
|
|||||||
|
|
||||||
string& fooRef = foo; // This creates a reference to foo.
|
string& fooRef = foo; // This creates a reference to foo.
|
||||||
fooRef += ". Hi!"; // Modifies foo through the reference
|
fooRef += ". Hi!"; // Modifies foo through the reference
|
||||||
cout << foo; // Prints "I am foo. Hi!"
|
cout << fooRef; // Prints "I am foo. Hi!"
|
||||||
|
|
||||||
fooRef = bar; // Error: references cannot be reassigned.
|
fooRef = bar; // Error: references cannot be reassigned.
|
||||||
|
|
||||||
@@ -373,6 +373,9 @@ public:
|
|||||||
|
|
||||||
// Overload the += operator
|
// Overload the += operator
|
||||||
Point& operator+=(const Point& rhs);
|
Point& operator+=(const Point& rhs);
|
||||||
|
|
||||||
|
// It would also make sense to add the - and -= operators,
|
||||||
|
// but we will skip those for brevity.
|
||||||
};
|
};
|
||||||
|
|
||||||
Point Point::operator+(const Point& rhs) const
|
Point Point::operator+(const Point& rhs) const
|
||||||
|
Reference in New Issue
Block a user