function name after enum

Write your question here.
Hello, in teach yourself c++ book I came across the code below
1
2
enum ERR_CODE{SUCCESS,ERROR};
ERR_CODE Factor(int, int&, int&);


When looking at the rest of the code I can undestand slightly how to use this function related with enum.

But can you please explain this declaration a little in detail?
enum function name?

can you give me other examples about how to use - type name function -

thanks in advance.
 
enum ERR_CODE{SUCCESS,ERROR};

This creates a new type ERR_CODE that has two possible values SUCCESS and ERROR.

 
ERR_CODE Factor(int, int&, int&);

This declares a function Factor that takes three arguments of type int, int& and int&, and returns a ERR_CODE.

When you call the function you can compare the return value to SUCCESS or ERROR to know if the function succeeded or not.
1
2
3
4
5
int a, b;
if (Factor(2, a, b) == ERROR)
{
	std::cout << "An error occurred!" << std::endl;
}
Thank you very much for your response, it's clearer now.
Topic archived. No new replies allowed.