Consider this very simple code:
#include <memory> class Foo { public: Foo() {}; }; class Bar { public: Bar( const std::shared_ptr<Foo>& foo ) {} }; int main() { Foo* foo = new Foo; Bar bar( std::shared_ptr<Foo>( foo ) ); return 0; }
Why Visual Studio Reports
warning C4930: 'Bar bar(std::shared_ptr<Foo>)': prototyped function not called (was a variable definition intended?)
and no object is created bar... how can this line Bar bar( std::shared_ptr<Foo>( foo ) );be interpreted as a function definition?
bar
Bar bar( std::shared_ptr<Foo>( foo ) );
I checked Does it contain parentheses after the type name with a new one? as well as C ++: warning: C4930: prototyped function not called (was this a variable definition?) , but I feel like my problem is different here since I did not use the syntax Foo()and Bar().
Foo()
Bar()
Edit: note that it successfully compiles:
Foo* foo = new Foo; std::shared_ptr<Foo> fooPtr( foo ); Bar bar( fooPtr );
++ . :
bar, bar foo std::shared_ptr<Foo>.
foo
std::shared_ptr<Foo>
. :
Bar bar( std::shared_ptr<Foo> foo);
, ++ 11 ( std::shared_ptr), :
std::shared_ptr
Bar bar(std::shared_ptr<Foo>{foo});
bar bar, - .
Source: https://habr.com/ru/post/1685671/More articles:Module build error: Error: could not find the predefined properties "transform-class-properties" relative to the directory - javascriptМожет ли кто-нибудь объяснить, что пролог делает с этой рекурсивной программой? - recursionInconsistent data in Chrome developer tools - javascriptError: could not find preinstalled "es2015" relative to directory - javascriptPython function references - pythonJava 8 Time API - ZonedDateTime - указать значение по умолчанию для ZoneId при разборе - javaЛюбая разница между java.time.Clock.systemDefaultZone(). GetZone() vs java.util.TimeZone.getDefault(). ToZoneId()? - javaReading CSV with line breaks in pyspark - python-3.xHow to speed up data retrieval and assign a value? - pythonДанные JSON не отображаются - javascriptAll Articles