You didn't give us the error, but my guess is that it was something along the lines of "function3 is not accessible". If that's the error, it is because the default access for class members is private.
In the snippet you posted, class second is private within first and function3 is private within class second.