473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Beginner question: Pass object as class parameter

Why do I get the error C2597: illegal reference to non-static member
'ClientProxy::User' (plus a bunch of other errors)?

Obviously I'm not defining the passing of an object into a class correctly.
How do I do this correctly?
/* ClientProxy.cpp */

#include "ClientProxy.h"
Campaign RequestCampaign(User CurrentUser);
Campaign ClientProxy::RequestCampaign(User CurrentUser) /* ERROR HERE */
{
return CurrentCampaign;
}
/* ClientProxy.h */

#ifndef __CLIENTPROXY__
#define __CLIENTPROXY__
#include "Campaign.h"
#include "User.h"

class ClientProxy
{
public:
Campaign RequestCampaign(User CurrentUser);

private:
Campaign CurrentCampaign;
User User;
};
/* END CLASS DEFINITION ClientProxy */
#endif /* __CLIENTPROXY__ */
Oct 13 '05 #1
7 4866
> Campaign RequestCampaign(User CurrentUser);
Campaign ClientProxy::RequestCampaign(User CurrentUser) /* ERROR HERE */
{
return CurrentCampaign;
}


What is that first line doing there? That may be a source of errors
since the function is not defined as a ClientProxy member function.
The second line above looks like the correct start of the function
definition.

Oct 13 '05 #2

James wrote:
Why do I get the error C2597: illegal reference to non-static member
'ClientProxy::User' (plus a bunch of other errors)?

Obviously I'm not defining the passing of an object into a class correctly.
How do I do this correctly?
/* ClientProxy.cpp */

#include "ClientProxy.h"
Campaign RequestCampaign(User CurrentUser);
Campaign ClientProxy::RequestCampaign(User CurrentUser) /* ERROR HERE */
{
return CurrentCampaign;
}
/* ClientProxy.h */

#ifndef __CLIENTPROXY__
#define __CLIENTPROXY__
#include "Campaign.h"
#include "User.h"

class ClientProxy
{
public:
Campaign RequestCampaign(User CurrentUser);

private:
Campaign CurrentCampaign;
User User;
This line is likely the source of the errors. The typename is used as a
variable name. Try:

User user_;

or something to that effect. Generally, people designate member
variables with some sort of tag (a prefixed or suffixed underscore or a
prefix of m_). Types are generally capitalized, and variable names
begin with a lower case letter. All this is merely stylistic, however.
};
/* END CLASS DEFINITION ClientProxy */
#endif /* __CLIENTPROXY__ */


Cheers! --M

Oct 13 '05 #3

"James" <ja***@hotmail.com> wrote in message
news:cX*************@newsfe2-gui.ntli.net...
Why do I get the error C2597: illegal reference to non-static member
'ClientProxy::User' (plus a bunch of other errors)?

Obviously I'm not defining the passing of an object into a class
correctly. How do I do this correctly?
/* ClientProxy.cpp */

#include "ClientProxy.h"
Campaign RequestCampaign(User CurrentUser);
That line's not needed. The function declaration is in the header, so you
don't put a prototype here.
Campaign ClientProxy::RequestCampaign(User CurrentUser) /* ERROR HERE */
{
return CurrentCampaign;
}
/* ClientProxy.h */

#ifndef __CLIENTPROXY__
#define __CLIENTPROXY__
#include "Campaign.h"
#include "User.h"

class ClientProxy
{
public:
Campaign RequestCampaign(User CurrentUser);

private:
Campaign CurrentCampaign;
User User;


Just guessing, but I suspect that this is the problem. You're giving the
type and the variable the same name. Change the variable name.

Personally, my variables start with small letters, and my types with capital
letters. Some people preface member variable names with "f" (for "field") or
"m_" (for "member").

-Howard
Oct 13 '05 #4
Howard wrote:
"James" <ja***@hotmail.com> wrote

[snip]
Campaign RequestCampaign(User CurrentUser);


That line's not needed. The function declaration is in the header, so you
don't put a prototype here.

[snip]

It's not needed unless there actually is a non-member function with
that signature. Given that this is a newbie question, it could go
either way, though if such a function does exist, it probably
shouldn't.

Cheers! --M

Oct 13 '05 #5
"mlimber" <ml*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Howard wrote:
"James" <ja***@hotmail.com> wrote

[snip]
> Campaign RequestCampaign(User CurrentUser);


That line's not needed. The function declaration is in the header, so
you
don't put a prototype here.

[snip]

It's not needed unless there actually is a non-member function with
that signature. Given that this is a newbie question, it could go
either way, though if such a function does exist, it probably
shouldn't.


OK, I followed all suggestions and it is now compiling.

Thanks people.
Oct 13 '05 #6
<An**********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Campaign RequestCampaign(User CurrentUser);
Campaign ClientProxy::RequestCampaign(User CurrentUser) /* ERROR HERE */
{
return CurrentCampaign;
}


What is that first line doing there? That may be a source of errors
since the function is not defined as a ClientProxy member function.
The second line above looks like the correct start of the function
definition.


The first line is there because Visio generated that line when it generated
the code from my class diagram. Being a beginner at C++ I guessed it had a
purpose, but obviously not.
Oct 13 '05 #7
mlimber <ml*****@gmail.com> wrote:
Generally, people designate member
variables with some sort of tag (a prefixed or suffixed underscore or a
prefix of m_).


You shouldn't prefix with an underscore. I believe the standard says
that names that start with an underscore followed by a capital letter,
and names with two underscores, are reserved for the implementation, so
to avoid the issue altogether, just avoid using underscores at the
beginning of a name.

--
Marcus Kwok
Oct 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

46
by: J.R. | last post by:
Hi folks, The python can only support passing value in function call (right?), I'm wondering how to effectively pass a large parameter, such as a large list or dictionary? It could achieved...
15
by: Pelle Beckman | last post by:
Hi all, I have a few newbie questions: In function declaration what does a 'const' mean inside the parameter list ? That it won't modify the value? void MemberFunction(const int x);
39
by: TonyJeffs | last post by:
Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK... I get line 12, but I wonder what...
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
13
by: ^MisterJingo^ | last post by:
I've been reading up on interfaces, one example I came across showed that you can hide a method implemented from an interface from the class which implements it. To use it, you must cast to the...
6
by: Chris | last post by:
Hi all, I've recently discovered the joys of tag :) I have a ListView which is populated with strings from a List<>, and each ListView item is linked to the relevant object in List<> using Tag....
4
by: 3rdshiftcoder | last post by:
hi- i am having trouble using parameter values in my function and to be honest a little trouble with member variables. i am trying to pass in the argument 'd' representing delete. what the...
4
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. ...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.