#Function call vs object construction

15 messages · Page 1 of 1 (latest)

last steppe
#

For example if I had foo(1,2); how does it know if I’m trying to call a function or trying to create an object foo? Is it because the compiler already has seen foo and would just resolve it based on what it knows.

sturdy wharfBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lucid prism
warm flame
noble musk
#

not even new is needed

#
struct X{
int i,j;
X(int i, int j) : i(i), j(j){}

};

int main(){
    X x = X(3,4);
    return x.i;
}
warm flame
#

But yeah either way just avoid such scenarios and you'll be fine. With proper naming it shouldn't happen

warm flame
#

If there's a naming conflict, the compiler might be able to figure it out from context or you'll just get an ambiguity error

#

Use nouns for types and verbs for functions and you'll be fine

lucid prism
left summit
#

it'll show an error for u

#

bc naming conflict