What are Operators and Inlines?

What are Operators and inline? I've read and typed the first 2 examples of operators from the book im reading. The author isnt explaining it very clearly to me. And doesnt go over much stuff in the examples. He brought in new stuff which was inline and operators. The operator is what the chapter is about. All I know about operators is that they're for objects i think. He didnt go over what inline is. If you could help me for how the problem below uses inline and operator, thatd be great. Also another thing, i see in the it says friend ostream& operator<<(ostream& os, const Critter& aCritter);. Do you not have to put string or int etx in front of os? I dont believe i made it a variable through out the whole code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
using namespace std;

class Critter
{
    friend void Peek(const Critter& aCritter);
    friend ostream& operator<<(ostream& os, const Critter& aCritter);
public:
    Critter(const string& name="");
private:
    string m_Name;
};

Critter::Critter(const string& name):
    m_Name(name)
    {}

void Peek(const Critter& aCritter);
ostream& operator<<(ostream& os, const Critter& aCritter);



int main()
{
    Critter crit("Poochie");
cout << "Calling Peek() to access crit's private data member, m_Name: \n";
Peek(crit);


    cout << "\nSending crit object to cout with the << operator:\n";
    cout << crit;

    return 0;
}

void Peek(const Critter& aCritter)
{
    cout << aCritter.m_Name << endl;
}

ostream& operator <<(ostream& os, const Critter& aCritter)
{
    os << "Critter Object - ";
    os << "m_Name: " << aCritter.m_Name;
    return os;
}
I differ thee to thy all-mighty reference:

Operator overloading: http://en.cppreference.com/w/cpp/language/operators
Inline specifier: http://en.cppreference.com/w/cpp/language/inline
Topic archived. No new replies allowed.