Skip to content

Commit 7067b82

Browse files
committed
Initialize base class in the copy constructor
1 parent 8eb2077 commit 7067b82

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

inst/include/Rcpp/Module.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ namespace Rcpp{
201201

202202
template <typename Class>
203203
class S4_CppConstructor : public Reference {
204+
typedef Reference Base;
204205
public:
205206
typedef XPtr<class_Base> XP_Class ;
206207
typedef Reference::Storage Storage ;
@@ -215,12 +216,13 @@ namespace Rcpp{
215216
field( "docstring" ) = m->docstring ;
216217
}
217218

218-
RCPP_CTOR_ASSIGN(S4_CppConstructor)
219+
RCPP_CTOR_ASSIGN_WITH_BASE(S4_CppConstructor)
219220

220221
} ;
221222

222223
template <typename Class>
223224
class S4_CppOverloadedMethods : public Rcpp::Reference {
225+
typedef Rcpp::Reference Base;
224226
public:
225227
typedef Rcpp::XPtr<class_Base> XP_Class ;
226228
typedef SignedMethod<Class> signed_method_class ;
@@ -253,7 +255,7 @@ namespace Rcpp{
253255

254256
}
255257

256-
RCPP_CTOR_ASSIGN(S4_CppOverloadedMethods)
258+
RCPP_CTOR_ASSIGN_WITH_BASE(S4_CppOverloadedMethods)
257259

258260
} ;
259261

@@ -317,6 +319,7 @@ namespace Rcpp{
317319

318320
template <typename Class>
319321
class S4_field : public Rcpp::Reference {
322+
typedef Rcpp::Reference Base;
320323
public:
321324
typedef XPtr<class_Base> XP_Class ;
322325
S4_field( CppProperty<Class>* p, const XP_Class& class_xp ) : Reference( "C++Field" ){
@@ -328,7 +331,7 @@ namespace Rcpp{
328331
field( "docstring" ) = p->docstring ;
329332
}
330333

331-
RCPP_CTOR_ASSIGN(S4_field)
334+
RCPP_CTOR_ASSIGN_WITH_BASE(S4_field)
332335

333336
} ;
334337

@@ -377,6 +380,7 @@ namespace Rcpp {
377380
}
378381

379382
class CppClass : public S4{
383+
typedef S4 Base;
380384
public:
381385
typedef XPtr<class_Base> XP_Class ;
382386
typedef Rcpp::XPtr<Rcpp::Module> XP ;
@@ -401,19 +405,20 @@ namespace Rcpp {
401405
slot( "parents" ) = cl->parents ;
402406
}
403407

404-
RCPP_CTOR_ASSIGN(CppClass)
408+
RCPP_CTOR_ASSIGN_WITH_BASE(CppClass)
405409

406410
} ;
407411

408412
class CppObject : public S4{
413+
typedef S4 Base;
409414
public:
410415
typedef Rcpp::XPtr<Rcpp::Module> XP ;
411416
CppObject( Module* p, class_Base* clazz, SEXP xp ) : S4("C++Object") {
412417
slot( "module" ) = XP( p, false ) ;
413418
slot( "cppclass" ) = Rcpp::XPtr<class_Base>( clazz, false ) ;
414419
slot( "pointer" ) = xp ;
415420
}
416-
RCPP_CTOR_ASSIGN(CppObject)
421+
RCPP_CTOR_ASSIGN_WITH_BASE(CppObject)
417422
} ;
418423

419424
}

inst/include/Rcpp/macros/interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ __CLASS__( const GenericProxy<Proxy>& proxy ){ \
3535
Storage::set__( proxy.get() ) ; \
3636
}
3737

38+
#define RCPP_CTOR_ASSIGN_WITH_BASE(__CLASS__) \
39+
__CLASS__( const __CLASS__& other ) : Base(other) { \
40+
} \
41+
__CLASS__& operator=(const __CLASS__& rhs) { \
42+
return Storage::copy__(rhs) ; \
43+
} \
44+
template <typename Proxy> \
45+
__CLASS__( const GenericProxy<Proxy>& proxy ){ \
46+
Storage::set__( proxy.get() ) ; \
47+
}
48+
3849
#define RCPP_API_CLASS(__CLASS__) \
3950
template < template <class> class StoragePolicy > class __CLASS__ : \
4051
public StoragePolicy<__CLASS__<StoragePolicy> >, \

0 commit comments

Comments
 (0)