Home
Blogs
Questions
Jobs
Monetize

Home

About Us

Blogs

Questions

Jobs

Monetize

Post Job

banner

Questions about copy-initialization

Read more about copy-initialization

python (65.2k questions)

javascript (44.3k questions)

reactjs (22.7k questions)

java (20.8k questions)

c# (17.4k questions)

html (16.3k questions)

r (13.7k questions)

android (13k questions)

Questions - copy-initialization

Why smart pointer type member variable can't be initialized at the declaring place in a class?

When I want to add a member variable with smart pointer type to a class, I found that it can't be initialized at the declaring place: class Foo { public: std::shared_ptr<int> intSharedPtr = n...
test-img

Zhang Zheng

c++

class

initialization

smart-pointers

copy-initialization

Votes: 0

Answers: 1

Latest Answer

std::shared_ptr can't be copy-initialized from raw pointer, the conversion constructor is marked as explicit. You can use direct-initialization: class Foo { public: std::shared_ptr<int> intSh...
test-img

songyuanyao

Posts

Questions

Blogs

Jobs

The ultimate platform for coders and IT specialists

About

  • Company
  • Support

  • Platform

  • Terms & Conditions
  • Privacy statement
  • Cookie policy
  • Cookie option
  • OnlyCoders © 2025  |  All rights reserved