If you don't understand the difference between an object and a type, then you're going to be in all sorts of trouble. It's absolutely fundamental to programming in C++, or in any typed language.
In a nutshell, consider the following statement:
i
is on object. It corresponds to a particular piece of memory, containing specific values.
int
is a type. It tells us something about how the values stored in memory are treated.
(Yes, it's unusual to consider a variable of a primitive type as an "object", but conceptually that's what they are.)
You can change the value of i - for example:
1 2 3 4 5
|
int i = 0;
i = 2;
i = 3 + 1;
i ++;
|
You cannot change the value of int, because int is not an object with a value. It is simply a type:
|
int = 1; // THIS MAKES NO SENSE
|
Nor can you read the value of int, because it has no value:
1 2
|
std::cout << "The value of int is " << int << std::cout; // THIS MAKES NO SENSE
|
Now consider:
i and j are two different objects. They correspond to different bits of memory, and hence can hold different values.
i and j have the same type. They are both int. They share the same behaviour, but hold different values.
Now consider the following, from your code:
infoType tele[]
Here, you are declaring an object. Its
name is
tele
. Its
type is an array of
infoType
objects - in other words, its type is a pointer to
infoType
, or
infoType*
.
Now look at your line:
|
if (infoType.lname[j] != "" && infoType.lname[smallest] != "")
|
infoType
is a type. Semantically, it is the equivalent of
int
. It has no value. It cannot be array-indexed. It cannot be read. It cannot be set to a value.
The name of the object that you have passed into your sort function is
tele
. That is the thing you should be looking at the values of.