Похожие чаты

Hi there, Why is this valid ? void test(int & ref); test(10);

11 ответов

21 просмотр

it is not.. void test(int&){} void foo() { test(10); } clang outputs: <source>:3:5: error: no matching function for call to 'test' test(10); ^~~~ <source>:1:6: note: candidate function not viable: expects an lvalue for 1st argument void test(int&){} ^

It's not

John- Автор вопроса
John- Автор вопроса
Danya🔥
It's not

Mine, It is valid.

John
MSVC ?

MSVC (19.27) reports <source>(3): error C2664: 'void test(int &)': cannot convert argument 1 from 'int' to 'int &' <source>(1): note: see declaration of 'test' Compiler returned: 2

John
Me gcc.

Doesn't matter, still not valid GCC reports <source>: In function 'void foo()': <source>:3:10: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' 3 | test(10); | ^~ <source>:1:11: note: initializing argument 1 of 'void test(int&)' 1 | void test(int&){} | ^~~~ Compiler returned: 1 For completeness sake, ICC reports <source>(3): error: initial value of reference to non-const must be an lvalue test(10); ^ compilation aborted for <source> (code 2) Compiler returned: 2

John- Автор вопроса
olli
Doesn't matter, still not valid GCC reports <sourc...

Wrong posting so sorry. Should be test(const int & i); test(10); Dont you think reference should be lvalue ?

John
Wrong posting so sorry. Should be test(const int &...

yes, that's fine. Why does it need to be an lvalue? Using a prvalue is fine and a const reference can exist to an xvalue. Another example of the same principle is passing a string literal to foo(const std::string&)

John- Автор вопроса
olli
yes, that's fine. Why does it need to be an lvalue...

I want to differ operation for constant and object (lvalue). Quite dont understand about prvalue and xvalue. Let me look at it. Anyway, Thanks.

John
I want to differ operation for constant and object...

Why do you want that? Why do you want a constant not to be considered a const reference? Otherwise you could look at rvalue references

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта