Related
McCamurry I have two functions whose signature cannot be changed. The first refers to an object, while the second refers to a generic reference to a unique pointer to the same object. I am not sure how to pass the first parameter to the second parameter. I've
RX_DID_RX Suppose I have the following class hierarchy: struct Base
{
};
struct Derived : public Base
{
void DoStuffSpecificToDerivedClass()
{
}
};
and the following factory method: std::unique_ptr<Base> factoryMethod()
{
auto derived =
RX_DID_RX Suppose I have the following class hierarchy: struct Base
{
};
struct Derived : public Base
{
void DoStuffSpecificToDerivedClass()
{
}
};
and the following factory method: std::unique_ptr<Base> factoryMethod()
{
auto derived =
RX_DID_RX Suppose I have the following class hierarchy: struct Base
{
};
struct Derived : public Base
{
void DoStuffSpecificToDerivedClass()
{
}
};
and the following factory method: std::unique_ptr<Base> factoryMethod()
{
auto derived =
RX_DID_RX Suppose I have the following class hierarchy: struct Base
{
};
struct Derived : public Base
{
void DoStuffSpecificToDerivedClass()
{
}
};
and the following factory method: std::unique_ptr<Base> factoryMethod()
{
auto derived =
RX_DID_RX Suppose I have the following class hierarchy: struct Base
{
};
struct Derived : public Base
{
void DoStuffSpecificToDerivedClass()
{
}
};
and the following factory method: std::unique_ptr<Base> factoryMethod()
{
auto derived =
Andrew Uknown I'm trying to pass a random number generator around my program (I want to use a generator), but I can't seem to find a way to pass it by reference. Here's what I've tried so far: #include <iostream>
#include <random>
#include <functional>
using
Andrew Uknown I'm trying to pass a random number generator around my program (I want to use a generator), but I can't seem to find a way to pass it by reference. Here's what I've tried so far: #include <iostream>
#include <random>
#include <functional>
using
code void f1(unique_ptr<A[]>& upA){
//some work...
//callee can mess up smart pointer many ways for caller
upA.reset();
//some work...
}
void f2(const unique_ptr<A[]>& upA){
//some work...
//compiler stops callee from ruining s
code void f1(unique_ptr<A[]>& upA){
//some work...
//callee can mess up smart pointer many ways for caller
upA.reset();
//some work...
}
void f2(const unique_ptr<A[]>& upA){
//some work...
//compiler stops callee from ruining s
code void f1(unique_ptr<A[]>& upA){
//some work...
//callee can mess up smart pointer many ways for caller
upA.reset();
//some work...
}
void f2(const unique_ptr<A[]>& upA){
//some work...
//compiler stops callee from ruining s
Praven struct cls{
~cls(){std::cout<<"dtor\n";}
};
void foo(cls** pp){
*pp = new cls;
}
int main()
{
cls* raw_ptr = 0;
foo(&raw_ptr);
std::unique_ptr<cls> u_ptr{raw_ptr};
}
Is there a way to directly access raw_pointerthe unique_ptrp
Praven struct cls{
~cls(){std::cout<<"dtor\n";}
};
void foo(cls** pp){
*pp = new cls;
}
int main()
{
cls* raw_ptr = 0;
foo(&raw_ptr);
std::unique_ptr<cls> u_ptr{raw_ptr};
}
Is there a way to directly access raw_pointerthe unique_ptrp
username How to pass std::unique_ptra to the function? Lets say I have the following classes: class A
{
public:
A(int val)
{
_val = val;
}
int GetVal() { return _val; }
private:
int _val;
};
The following will not compile: void My
User3690202: How to pass std::unique_ptra to the function? Lets say I have the following classes: class A
{
public:
A(int val)
{
_val = val;
}
int GetVal() { return _val; }
private:
int _val;
};
The following will not compile: voi
User3690202: How to pass std::unique_ptra to the function? Lets say I have the following classes: class A
{
public:
A(int val)
{
_val = val;
}
int GetVal() { return _val; }
private:
int _val;
};
The following will not compile: voi
Matthias Price I have the following working code initialized std::unique_ptrwith a custom deleter : class Dataset
{
...
private:
class CustomGDALDatasetDeleter {
public:
void operator()(GDALDatasetH res) const {
::GDALCl
Matthias Price I have the following working code initialized std::unique_ptrwith a custom deleter : class Dataset
{
...
private:
class CustomGDALDatasetDeleter {
public:
void operator()(GDALDatasetH res) const {
::GDALCl
InKodeWeTrust Having trouble compiling the following. I created a function object and tried to pass a unique pointer, but the compiler complained that I was trying to access private data in the unique_ptr. This happened in msvc 2012 v110. class Work
{
};
clas
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
and On the surface, I like unique_ptrthe schema of having containers to own data. My question is, is it safe to take a pointer/reference to a member of such an object if I know it unique_ptrwon't go out of scope ? For example I might have auto v = std::vector<
username I'm trying to keep a reference to another object in a class, so I'm using pointers as members. What is the best way to pass a reference and what is the difference between them. class Sprite
{
public:
Sprite();
void SetTexture(Texture * const&
username I'm trying to keep a reference to another object in a class, so I'm using pointers as members. What is the best way to pass a reference and what is the difference between them. class Sprite
{
public:
Sprite();
void SetTexture(Texture * const&
username I'm trying to keep a reference to another object in a class, so I'm using pointers as members. What is the best way to pass a reference and what is the difference between them. class Sprite
{
public:
Sprite();
void SetTexture(Texture * const&
Magic DM #include <functional>
#include <memory>
#include <string>
#include <iostream>
void foo(std::function<void()> f)
{
f();
}
int main()
{
std::unique_ptr<int> handle = std::make_unique<int>(5);
foo(
[h = std::move(handle)]() mutable