none none
none none

Reputation: 343

Shorthand for using multiple names from the same C++ namespace

I'm writing a chess program and I've defined the classes I've created under the chess namespace.

To shorten the code in files that use those classes, I preface it with using chess::Point, chess::Board, chess::Piece and so on.

Is there a way to specify that I'm bringing in scope multiple elements from the same namespaces like in Rust? (Such as use chess::{Point,Board,Piece}.)

Upvotes: 1

Views: 486

Answers (2)

Ch3steR
Ch3steR

Reputation: 20689

You could use namespace alias instead of bringing everything into the scope. Create a shorter alias for chess.

namespace ch = chess;
// ch::Point, ch::Board, ch::Piece // all are valid.

Upvotes: 3

No. But you can bring them all at once, using:

using namespace chess;

// then use Point instead of chess::Point, Board instead of chess::Board, etc

Upvotes: 2

Related Questions