I am in need of clarification. I am still a 'noob' when it comes too C++. I get a lot of the basic stuff except passing arguments.
I understand that you can pass by reference and by pointer and by copy. but things start getting really confusing from that point on. Probably not a new problem heard of before on the discussion forums. However if someone can help me out here.
Lets say I have a type
class SOME_TYPE{
private:
string name;
int value;
public:
SOME_TYPE(){ //constructor
}
string GetName(){
return name;
}
void SetName(string nname){
name = nname;
}
int GetValue(){
return value;
}
void SetValue(int amount){
value = amount;
}
};
lets say I have a list of pointers to that type
SOME_TYPE* list[5]; //I'm assuming this is how you write a list of pointers
Now I want to send that list over to another method to display their values.
void DisplayList(SOME_TYPE* list){
for(int loop = 0; loop < 5; loop++){
if(list[loop] != NULL){
cout << list[loop]->GetName() << " - Value: " << list[loop]->GetValue() << endl;
}
}
}
int main(){
SOME_TYPE* list[5];
list[0]->SetName("one");
list[0]->SetValue(1);
list[1]->GetName("two");
list[1]->SetValue(2);
DisplayList(list);
return;
}
Now here is where I am getting frustrated. Is the 'DisplayList" method asking for the correct argument? I am assuming it is asking for a pointer to the beginning of a list. Since 'list' declared in main is a list of pointers am I sending it the correct way? Can someone please correct my understanding and explain to me how pointers are handled?