Wrox Programmer Forums
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion 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 April 5th, 2012, 01:43 PM
Registered User
 
Join Date: Apr 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Passing Class Instance to a Function

Greetings.
I am writing a programme that uses dialog 'screens' to gather data. It uses list boxes and edit boxes which need setting with default values, or after use the user's entered value/script. requires a number of list box.
To clarify the code I wish to put this initiation and retreval (DDV & DDX) into functions, but I cannot seem to define them correctly - have written simple test routine - relevant parts and comments copied below.

I am using "Microsoft Visual Studio 2010 Proffesional"

Any assistance would be appreciated.

Code:
// from		"CTester_V10View::CTester_V10View()"
//
s_ReturnString = _T("source message");

// from Dialog .h file
//
CString s_DialogString;

// *****************************************************************

void CTester_V10View::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	TestDialog Tester;				// Declare instance of dialog 
	SetUp(Tester);					// call routine to set up Dialog

	if(Tester.DoModal() == IDOK)			// Return from dialog box
		s_ReturnString = Tester.s_DialogString;		// get returned 
                                                                // string from dialog edit box
	CView::OnLButtonDown(nFlags, point);
}

// *****************************************************************
// Declaration of this function is the problem !
//
int CTester_V10View::SetUp(const TestDialog& Fred)	// test function
													// sets up initial string in edit box
{
	Fred.s_DialogString = s_ReturnString;		// s_ReturnString set to initial test 
							// string in "CTester_V10View()"
	return 0;
}

// *****************************************************************
// Declarations tried and failed
//
//	Declarations giving error messages of 
//  "incompattible with declaration in .h file" against "SetyUp"
//
int CTester_V10View::SetUp(const TestDialog &Fred)
int CTester_V10View::SetUp(const TestDialog& Fred)

// * - Explicit type is missing
// "Fred" Expected a ')'
//
int CTester_V10View::SetUp(const *TestDialog Fred)

//No operator '=' matches these operands i.e. in body of function
// for "Fred.s_DialogString = s_ReturnString;"
//
int CTester_V10View::SetUp(const class TestDialog Fred)
int CTester_V10View::SetUp(const class TestDialog& Fred)

// On build following error message.
// error C2678: binary '=' : no operator found which takes a left-hand operand of 
// type 'const CString' (or there is no acceptable conversion)
//
int CTester_V10View::SetUp(const class TestDialog &Fred)
As a new member I trust that I have posted in the correct place.





Similar Threads
Thread Thread Starter Forum Replies Last Post
What instance? - Data-binding to my class stevefal Pro Visual Basic 2005 0 April 15th, 2008 06:02 PM
static field with class instance prakash.suthar Java Basics 2 July 3rd, 2006 01:41 AM
Instance of same class in main method ajit Java Basics 1 July 1st, 2006 06:26 PM
How do I refer to a class instance in VB? James Diamond Beginning VB 6 7 February 9th, 2004 03:31 PM
How to create a class instance dynamic??? ffbalota C# 0 September 21st, 2003 04:49 PM





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