Click here to Skip to main content
15,923,389 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
AnswerRe: Event on KeyPress Pin
Mark Salsbery26-Jul-08 9:55
Mark Salsbery26-Jul-08 9:55 
GeneralRe: Event on KeyPress Pin
Polar_Sheep26-Jul-08 10:03
Polar_Sheep26-Jul-08 10:03 
GeneralRe: Event on KeyPress [modified] Pin
Mark Salsbery26-Jul-08 10:16
Mark Salsbery26-Jul-08 10:16 
AnswerRe: Event on KeyPress Pin
Polar_Sheep26-Jul-08 10:22
Polar_Sheep26-Jul-08 10:22 
GeneralRe: Event on KeyPress Pin
Polar_Sheep26-Jul-08 10:25
Polar_Sheep26-Jul-08 10:25 
GeneralRe: Event on KeyPress Pin
Mark Salsbery26-Jul-08 10:35
Mark Salsbery26-Jul-08 10:35 
AnswerRe: Event on KeyPress Pin
dybs29-Jul-08 18:34
dybs29-Jul-08 18:34 
QuestionAssignment Operator Woes [modified] Pin
DemSmiley23-Jul-08 17:41
DemSmiley23-Jul-08 17:41 
This is a problem I've had since I started using C++/CLI
take for example this simple ref class
ref class CFoo
{
  public:
    String^ text;

    CFoo(void)
    {
      this->text = "";
    }

    CFoo(const CFoo^ _cpy)
    {
      this->text = _cpy->text;
    }

    void operator=(const CFoo^ _rhs)
    {
       this->text = _rhs->text;
    }
};


And now a main that has a couple CFoo variables

int main(void)
{
  CFoo^ foo1 = gcnew CFoo();
  CFoo^ foo2 = gcnew CFoo();

  foo1->text = "Bill";
  foo2 = foo1;
  foo1->text = "Bob";

  return 0;
}


When I run this when I run foo2 = foo1;" my assignment operator is never called and all that happens is the handle from foo1 is given to foo2. Then when I change the text of foo1 it "changes" foo2 which is just at this point a reference to foo1;

Now if I swap out
foo2 = foo1;

with
foo2->operator =(foo1);

then everything works as I expect it.
The way I have always gotten around this was to call the copy constructor like so
foo2 = gcnew CFoo(foo1);

Although this works in my opinion it doesn't look as nice as a simple = operator.
So what I'm looking for is to get foo1 = foo2; to call my assignment operator or is it just not possible? I've googled it to death and although its not stopping my program from working it's been something thats been bugging me to death.

modified on Thursday, July 24, 2008 12:05 AM

AnswerRe: Assignment Operator Woes Pin
Mark Salsbery24-Jul-08 5:41
Mark Salsbery24-Jul-08 5:41 
AnswerRe: Assignment Operator Woes Pin
led mike24-Jul-08 6:11
led mike24-Jul-08 6:11 
AnswerRe: Assignment Operator Woes Pin
Mark Salsbery24-Jul-08 7:31
Mark Salsbery24-Jul-08 7:31 
QuestionC++ code to access .NET component. Pin
Sitaram Sukumar22-Jul-08 1:33
Sitaram Sukumar22-Jul-08 1:33 
AnswerRe: C++ code to access .NET component. Pin
Mark Salsbery22-Jul-08 4:28
Mark Salsbery22-Jul-08 4:28 
QuestionDirectory:: move Pin
VCsamir21-Jul-08 21:48
VCsamir21-Jul-08 21:48 
AnswerRe: Directory:: move Pin
Mark Salsbery22-Jul-08 4:39
Mark Salsbery22-Jul-08 4:39 
GeneralRe: Directory:: move Pin
VCsamir22-Jul-08 19:20
VCsamir22-Jul-08 19:20 
GeneralRe: Directory:: move Pin
Mark Salsbery23-Jul-08 6:10
Mark Salsbery23-Jul-08 6:10 
QuestionExtending Managed, Sealed Classes in C++/CLI Pin
Skippums21-Jul-08 8:28
Skippums21-Jul-08 8:28 
AnswerRe: Extending Managed, Sealed Classes in C++/CLI Pin
Mark Salsbery21-Jul-08 10:20
Mark Salsbery21-Jul-08 10:20 
QuestionRe: Extending Managed, Sealed Classes in C++/CLI Pin
Skippums22-Jul-08 3:32
Skippums22-Jul-08 3:32 
AnswerRe: Extending Managed, Sealed Classes in C++/CLI Pin
Mark Salsbery22-Jul-08 4:29
Mark Salsbery22-Jul-08 4:29 
AnswerRe: Extending Managed, Sealed Classes in C++/CLI Pin
Luc Pattyn22-Jul-08 4:30
sitebuilderLuc Pattyn22-Jul-08 4:30 
QuestionMultiple forms calling same form object Pin
Xaria20-Jul-08 15:44
Xaria20-Jul-08 15:44 
QuestionWindows Service (C++/CLI) and MFC Pin
xuesyuan17-Jul-08 10:51
xuesyuan17-Jul-08 10:51 
AnswerRe: Windows Service (C++/CLI) and MFC Pin
Mark Salsbery17-Jul-08 11:08
Mark Salsbery17-Jul-08 11:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.