Related
sl Consider the following vector: std::vector<std::shared_ptr<X>> myVector;
and the following two functions that add a given element to a vector: void foo1(std::shared_ptr<X> x)
{
myVector.push_back(x);
}
void foo2(const std::shared_ptr<X>& x)
{
myVe
sl Consider the following vector: std::vector<std::shared_ptr<X>> myVector;
and the following two functions that add a given element to a vector: void foo1(std::shared_ptr<X> x)
{
myVector.push_back(x);
}
void foo2(const std::shared_ptr<X>& x)
{
myVe
sl Consider the following vector: std::vector<std::shared_ptr<X>> myVector;
and the following two functions that add a given element to a vector: void foo1(std::shared_ptr<X> x)
{
myVector.push_back(x);
}
void foo2(const std::shared_ptr<X>& x)
{
myVe
sl Consider the following vector: std::vector<std::shared_ptr<X>> myVector;
and the following two functions that add a given element to a vector: void foo1(std::shared_ptr<X> x)
{
myVector.push_back(x);
}
void foo2(const std::shared_ptr<X>& x)
{
myVe
Indigo 3 I have a function that needs to take shared ownership of a parameter, but not modify it. I have made the parameter shared_ptr <const T> to clearly communicate this intent. template <typename T>
void func(std::shared_ptr<const T> ptr){}
I want to call
Indigo 3 I have a function that needs to take shared ownership of a parameter, but not modify it. I have made the parameter shared_ptr <const T> to clearly communicate this intent. template <typename T>
void func(std::shared_ptr<const T> ptr){}
I want to call
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Sam Martens Suppose I have a class class K
{
public:
int k = 0;
void Change()
{
k++;
}
void None() const
{
std::cout << "None \n";
}
};
Why is it perfectly fine to use a non const method on a const reference li
Barry In short, is it better to pass pointers by value or const reference? I wrote a simple function to explore: void foo(int* v) { std::cout << *v << endl; }
and void foo(int* const& v) { std::cout << *v << endl; }
I tried looking at the generated assembly,
Arun Kumar First, there are a bunch of similar posts that look exactly the same, but I found them to be different from my problem. I am trying to use smart pointers for the first time in my C++ life. I'm having trouble with polymorphism with smart pointers. To
Arun Kumar First, there are a bunch of similar posts that look exactly the same, but I found them to be different from my problem. I am trying to use smart pointers for the first time in my C++ life. I'm having trouble with polymorphism with smart pointers. To
band Suppose we have the following function: void doStuff(const std::vector<std::shared_ptr<const Foo>>& fs) { }
Is there a way to (safely) pass a std::vector<std::shared_ptr<Foo>>to this parameter? E.g: std::vector<std::shared_ptr<Foo>> foos;
doStuff(foos);
band Suppose we have the following function: void doStuff(const std::vector<std::shared_ptr<const Foo>>& fs) { }
Is there a way to (safely) pass a std::vector<std::shared_ptr<Foo>>to this parameter? E.g: std::vector<std::shared_ptr<Foo>> foos;
doStuff(foos);
band Suppose we have the following function: void doStuff(const std::vector<std::shared_ptr<const Foo>>& fs) { }
Is there a way to (safely) pass a std::vector<std::shared_ptr<Foo>>to this parameter? E.g: std::vector<std::shared_ptr<Foo>> foos;
doStuff(foos);
band Suppose we have the following function: void doStuff(const std::vector<std::shared_ptr<const Foo>>& fs) { }
Is there a way to (safely) pass a std::vector<std::shared_ptr<Foo>>to this parameter? E.g: std::vector<std::shared_ptr<Foo>> foos;
doStuff(foos);
band Suppose we have the following function: void doStuff(const std::vector<std::shared_ptr<const Foo>>& fs) { }
Is there a way to (safely) pass a std::vector<std::shared_ptr<Foo>>to this parameter? E.g: std::vector<std::shared_ptr<Foo>> foos;
doStuff(foos);
Beko Suppose I declare a std::shared_ptr<const T>function that accepts parameters: void func(std::shared_ptr<const T> ptr);
Will the function accept calls std::shared_ptr<T>passing a ? Barry If you look at the constructors , two of them are:std::shared_ptr te
Beko Suppose I declare a std::shared_ptr<const T>function that accepts parameters: void func(std::shared_ptr<const T> ptr);
Will the function accept calls std::shared_ptr<T>passing a ? Barry If you look at the constructors , two of them are:std::shared_ptr te
Beko Suppose I declare a std::shared_ptr<const T>function that accepts parameters: void func(std::shared_ptr<const T> ptr);
Will the function accept calls std::shared_ptr<T>passing a ? Barry If you look at the constructors , two of them are:std::shared_ptr te
Beko Suppose I declare a std::shared_ptr<const T>function that accepts parameters: void func(std::shared_ptr<const T> ptr);
Will the function accept calls std::shared_ptr<T>passing a ? Barry If you look at the constructors , two of them are:std::shared_ptr te
patatahooligan In my case it Tis pcl::PointCloud<pcl::PointXYZ>>, but questions 768,16 represent any type T. The following example produces an error: using pc = pcl::PointCloud<pcl::PointXYZ> >;
boost::shared_ptr<pc> p(new pc);
boost::shared_ptr<const pc> cons
patatahooligan In my case it Tis pcl::PointCloud<pcl::PointXYZ>>, but questions 768,16 represent any type T. The following example produces an error: using pc = pcl::PointCloud<pcl::PointXYZ> >;
boost::shared_ptr<pc> p(new pc);
boost::shared_ptr<const pc> cons
patatahooligan In my case it Tis pcl::PointCloud<pcl::PointXYZ>>, but questions 768,16 represent any type T. The following example produces an error: using pc = pcl::PointCloud<pcl::PointXYZ> >;
boost::shared_ptr<pc> p(new pc);
boost::shared_ptr<const pc> cons
patatahooligan In my case it Tis pcl::PointCloud<pcl::PointXYZ>>, but questions 768,16 represent any type T. The following example produces an error: using pc = pcl::PointCloud<pcl::PointXYZ> >;
boost::shared_ptr<pc> p(new pc);
boost::shared_ptr<const pc> cons
y8natan compileg++ -std=c++11 -pedantic-errors -Wall -Wextra -g void foo(std::shared_ptr<Base>& ptr) {
std::cout << "foo()\n";
std::cout << "count = " << ptr.use_count() << "\n";
}
int main(int argc, char* argv[]) {
auto d = std::make_shared<