Wrox Programmer Forums
|
Visual C++ 2005 For discussion of Visual C++ 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2006, 07:24 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Returning an Object

I'm trying to learn Visual c++ 2005, I'm running into a problem returning objects in a function. I wrote a class called Point that stores x, y coordinates


Code:
ref class MyPoint 
{ 
private: 
  int x; 
  int y; 
public: 
  int getX();
  int getY();
  void setX(int newVal);
  void setY(int newVal);
};
And I have another class that stores a group of points:

Code:
ref class GroupOfPoints 
{ 
private: 
  MyPoint a; 
  MyPoint b; 
public: 
  MyPoint getPointA() { return a; } 
  MyPoint getPointB() { return b; } 
};

But it's giving me a compiler error for my 'get' functions like, "cannot convert MyPoint to MyPoint" which I don't really understand since they're the same thing aren't they?

I've looked at the msdn help and all they provide is:

Code:
typedef struct   
{ 
    char name[20]; 
    int id; 
    long class; 
} STUDENT; 
 
/* Return type is STUDENT: */ 
 
STUDENT sortstu( STUDENT a, STUDENT b ) 
{ 
    return ( (a.id < b.id) ? a : b ); 
}
Which is all fine and good and stuff but I'm trying to use their managed classes, not structures... Then the help goes on to say that I should return a reference which I kinda understand how to do in the old C++ format using "*'s" and "&'s" for native heap stuff. But the new C++ 2005 uses "^" for the managed heap and I can't find any examples on how to return a reference using the new syntax.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a recordset John Pennington VB Databases Basics 8 August 18th, 2008 08:37 AM
help on returning records memewang Crystal Reports 0 April 14th, 2007 08:48 PM
returning null value Vince_421 Access VBA 3 March 6th, 2007 01:54 PM
Returning a value Neal XSLT 6 October 13th, 2006 11:41 AM
Function not returning value civa Access 5 January 17th, 2006 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.