Membership of the Catholic Church is necessary for all men for salvation
That is a misleading generalization. Membership in the church is necessary for those who know of the church and its role in salvation. Salvation is denied to those who know the Church's role and willfully reject it; those who do no not know but nevertheless live upright lives can attain salvation. The official teaching of the Church (edit: I see BTS quoted this too), is in articles 846 and 847 of the Catechism (source: Vatican web site, emphasis: mine).
846 ... He himself explicitly asserted the necessity of faith and Baptism, and thereby affirmed at the same time the necessity of the Church which men enter through Baptism as through a door. Hence they could not be saved who, knowing that the Catholic Church was founded as necessary by God through Christ, would refuse either to enter it or to remain in it.
847 This affirmation is not aimed at those who, through no fault of their own, do not know Christ and his Church:
Those who, through no fault of their own, do not know the Gospel of Christ or his Church, but who nevertheless seek God with a sincere heart, and, moved by grace, try in their actions to do his will as they know it through the dictates of their conscience - those too may achieve eternal salvation.