473,387 Members | 1,590 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,387 software developers and data experts.

Class Initialization

Hello,

I have a class as follows:

public class UserPaper {
public MembershipUser user { get; set; }
public string Password { get; set; }

public UserLeaf(MembershipUser newUser) {
UserLeaf(newUser, null);
}
public UserLeaf(MembershipUser newUser, string password) {
this user = newUser;
this password = password;
}
}

I simplified my code but basically I get the following error:
'UserPaper' is a 'type' but is used like a 'variable'

Do I need to repeat the definition in all methods? I am a little bit
confused.

Thanks,
Miguel
Oct 31 '08 #1
3 1923
shapper wrote:
Hello,

I have a class as follows:

public class UserPaper {
public MembershipUser user { get; set; }
public string Password { get; set; }

public UserLeaf(MembershipUser newUser) {
UserLeaf(newUser, null);
}
public UserLeaf(MembershipUser newUser, string password) {
this user = newUser;
this password = password;
}
}

I simplified my code but basically I get the following error:
'UserPaper' is a 'type' but is used like a 'variable'

Do I need to repeat the definition in all methods? I am a little bit
confused.
I think you want the following:

public class UserPaper {
public MembershipUser User { get; set; }
public string Password { get; set; }

public UserPaper(MembershipUser newUser): this(newUser, null){

}
public UserPaper(MembershipUser newUser, string newPassword) {
User = newUser;
Password = newPassword;
}
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 31 '08 #2
Your class is called "UserPaper" but there are constructor-like members
called "UserLeaf". Constructors must have the same name as the class.

Secondly, you need to chain the first constructor onto the second as
follows:

public class UserPaper
{
// snip

public UserPaper(MembershipUser newUser) : this(newUser, null)
{
}

public UserPaper(MembershipUser newUser, string password)
{
this.user = newUser;
this.password = password;
}
}
"shapper" <md*****@gmail.comwrote in message
news:6c**********************************@40g2000p rx.googlegroups.com...
Hello,

I have a class as follows:

public class UserPaper {
public MembershipUser user { get; set; }
public string Password { get; set; }

public UserLeaf(MembershipUser newUser) {
UserLeaf(newUser, null);
}
public UserLeaf(MembershipUser newUser, string password) {
this user = newUser;
this password = password;
}
}

I simplified my code but basically I get the following error:
'UserPaper' is a 'type' but is used like a 'variable'

Do I need to repeat the definition in all methods? I am a little bit
confused.

Thanks,
Miguel

Oct 31 '08 #3
On Oct 31, 2:44*pm, "Clive Dixon" <clived at digita dot comwrote:
Your class is called "UserPaper" but there are constructor-like members
called "UserLeaf". Constructors must have the same name as the class.

Secondly, you need to chain the first constructor onto the second as
follows:

public class UserPaper
{
* * // snip

* * public UserPaper(MembershipUser newUser) : this(newUser, null)
* * {
* * }

* * public UserPaper(MembershipUser newUser, string password)
* * {
* * * this.user = newUser;
* * * this.password = password;
* * }

}
"shapper" <mdmo...@gmail.comwrote in message

news:6c**********************************@40g2000p rx.googlegroups.com...
Hello,
I have a class as follows:
*public class UserPaper {
* *public MembershipUser user { get; set; }
* *public string Password { get; set; }
* *public UserLeaf(MembershipUser newUser) {
* * *UserLeaf(newUser, null);
* *}
* *public UserLeaf(MembershipUser newUser, string password) {
* * *this user = newUser;
* * *this password = password;
* *}
}
I simplified my code but basically I get the following error:
'UserPaper' is a 'type' but is used like a 'variable'
Do I need to repeat the definition in all methods? I am a little bit
confused.
Thanks,
Miguel
The UserPaper and UserLeaf was a mistake when copying the code here.
For sake of simplicity I didn't copy paste the entire code and I wrote
it wrong.

But yes your answers were what I was looking for.

Thank You!
Miguel
Oct 31 '08 #4

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

Similar topics

106
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the...
8
by: Stub | last post by:
In statement: Circle c1=c2; Is the assignment operator= of Circle called? In statement Circle c1(c2); Is the copy constructor called?
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
3
by: J.J. Feminella | last post by:
(Please disregard the previous message; I accidentally sent it before it was completed.) I have source code similar to the following. public class Vehicle { protected string dataV; // ......
11
by: DrNoose | last post by:
Hi! I've got a program that's almost done, but I'm getting compile errors in two lines: 317 & 319. I think the main error has to do with the Truck Class. I'm a newbie and keep looking at the...
12
by: Christoph Zwerschke | last post by:
Usually, you initialize class variables like that: class A: sum = 45 But what is the proper way to initialize class variables if they are the result of some computation or processing as in...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
6
by: jmarcrum | last post by:
Hi everyone! I'm using a super class (DVD.java) that handles another class (EnhancedDVD.java). I want to pass the "details" of the DVD into the super class DVD.java. The super class contains the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.