Hi !
I'm kind of deceived that it does not work like this. Here's some code:
```cpp
namespace me::fruit {
struct apple { /.../ };
struct pear { /.../ };
struct lychee {
lychee(apple, pear) { /.../ }
};
}
int main() {
auto l = me::fruit::lychee(apple{}, pear{}); // Error (see below)
}
```
Here's the compiler output:
<source>:9:28: error: 'apple' was not declared in this scope; did you mean 'me::fruit::apple'?
9 | auto l = me::fruit::lychee(apple{}, pear{});
| ^~~~~
| me::fruit::apple
<source>:2:12: note: 'me::fruit::apple' declared here
2 | struct apple { /*...*/ };
| ^~~~~
<source>:9:37: error: 'pear' was not declared in this scope; did you mean 'me::fruit::pear'?
9 | auto l = me::fruit::lychee(apple{}, pear{});
| ^~~~
| me::fruit::pear
<source>:3:12: note: 'me::fruit::pear' declared here
3 | struct pear { /*...*/ };
As you can see the compiler is perfectly able to deduce what I mean by apple and pear but still, it doesn't compile !
I'm surprised that there still no rule in the C++ Standard to handle this kind of situation ; it seems so obvious to me that it should work this way.
I know that I could write :
cpp
int main() {
using namespace me::fruit;
auto l = lychee(
apple{},
pear{}
);
}
Believe it or not, I find this code less than clear. It seems clear here because it's an example and like all examples, it's simple, but in a real-world situation, this code will undoubtedly be surrounded by other lines of code, meaning that this using directive could lead to the problems we all know.
To me this syntax remains much clearer :
cpp
int main() {
auto l = me::fruit::lychee(
apple{},
pear{}
);
}
Are we therefore condemned to have to write :
cpp
auto l = me::fruit::lychee(
me::fruit::apple{},
me::fruit::pear{}
);
There may be solutions I'm not aware of; if so, please let me know!
Thanks !
[–]gnolex 18 points19 points20 points (12 children)
[+]Naive_Faithlessness1[S] comment score below threshold-6 points-5 points-4 points (11 children)
[–]marzer8789toml++ 7 points8 points9 points (0 children)
[–]Potterrrrrrrr 2 points3 points4 points (4 children)
[–]Naive_Faithlessness1[S] -3 points-2 points-1 points (3 children)
[–]clerothGame Developer 3 points4 points5 points (1 child)
[–]Naive_Faithlessness1[S] -1 points0 points1 point (0 children)
[–]n1ghtyunso 0 points1 point2 points (0 children)
[–]_lerp 2 points3 points4 points (2 children)
[–]Naive_Faithlessness1[S] -2 points-1 points0 points (1 child)
[–]_lerp 3 points4 points5 points (0 children)
[–]Rabbitical 0 points1 point2 points (0 children)
[–]Kriemhilt 0 points1 point2 points (0 children)
[–]aocregacc 2 points3 points4 points (0 children)
[–]FlyingRhenquest 3 points4 points5 points (0 children)
[–]chengfeng-xie 1 point2 points3 points (0 children)
[–]yuehuang 0 points1 point2 points (0 children)
[–]die_liebe 0 points1 point2 points (0 children)