Solved

C++ / CLI Copy Constructor grief

Posted on 2009-05-19
2
1,016 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

820 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