Yes, your approach should work just fine.
The advantage of using a class is that it can hold internal attributes you would have to pass otherwise to your functional approach.
E.g. using nn.CrossEntropyLoss, you could define the weight or reduction argument while creating an instance of this class. If you are using the functional method (F.cross_entropy), you would need to pass these arguments in each call.
While this might be cumbersome in some cases, it might make the code cleaner e.g. if you need to change the weight argument often.
Both APIs have some advantages and disadvantages and you can chose whatever feels right and makes the code clean.