Solved

C++ / CLI Copy Constructor grief

Posted on 2009-05-19
2
983 Views
Last Modified: 2012-05-07
I'm converting another project from Managed Extensions for C++ (.Net 1.1) to C++/CLI (.Net 2+)

In this project we have some copy constructors.

Following http://www.functionx.com/cppcli/classes/Lesson13b.htm I have my copy constructor declared as
Shift(const Shift^ &otherShift);

The code that used to call it is:
Object ^Shift::Clone(){
      return gcnew Shift(*this);
}
But this raises the compile error C3073: 'MyNamespace::Shift' : ref class does not have a user-defined copy constructor.

I've tried (&this), (this), (%this) -- all with varying errors.

So ... how do I call this copy constructor?

Thanks!
0
Comment
Question by:Daniel Wilson
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 24428891
Instead of
Shift(const Shift^ &otherShift);
how about
Shift(Shift^ otherShift);


and called with this
Object ^Shift::Clone(){
      return gcnew Shift(this);
}
0
 
LVL 32

Author Closing Comment

by:Daniel Wilson
ID: 31583311
That compiles ... I think you got it.

Thanks!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now