I see functions of the type:
data_type *function_name(arguments...)
and:
data_type function_name(arguments...)
I'm trying to learn when which one should be used. Why is this done in the example below? (This is from a textbook for a course.) When should I write functions like these?
struct Tower
{
string name;
Tower *link;
};
Tower *createTower(string name, Tower *link);
Further can someone clarify this?
Tower* createTower(string name, Tower *link)
{
Tower* tp = new Tower;
tp->name = name;
tp->link = link;
return tp;
}
Tower* createBeconsOfGondor(){
Tower *tp = createTower("Rohan", NULL); // Points to nothing
tp = createTower("Halifiren", tp); // Still returns pointer?
}
In the second line of the createBeconsOfGondor() function, how is the return of that function still a pointer?