user124950
user124950

Reputation: 23

Emulate Import as functionality from python in C++

In python I can do:
from long_and_painful import still_way_to_long as short

In C++ I am stuck with:

using long::and::painful::stillWayToLong;
... //Code and Stuff
stillWayToLong("Why must I type this so often?");

Am I missing something that would make this more pythonic?

Upvotes: 0

Views: 48

Answers (1)

Loki Astari
Loki Astari

Reputation: 264571

How about

auto x = long::and::painful::stillWayToLong;  // If this is an object/function
x("Why must I type this so often?");


using X = typename long::and::painful::stillWayToLong; // If this is a type.
X bob;

Upvotes: 1

Related Questions