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

class inaccessible

I am getting a message for my objects that say:

testNulls.cs(13,33): error CS0122: 'FtsData.IntType.IntType()' is
inaccessible due to its protection level

I have a class calling objects out of another class, but same namespace.

This is the class that gets the error:
************************************************** ************
namespace FtsData
{
[Serializable]
public class TestNulls
{
private IntType testNullsID = new IntType(); <---------
Error line
private StringType firstName = new StringType();
private DecimalType salary = new DecimalType();

public TestNulls()
{
salary.Data = 12345;
}
....
************************************************** **********

The class that defines the IntType objects:
*************************************************
using System;

namespace FtsData
{
[Serializable]
public class IntType
{
private int first = 0; //original data
private int data = 0; //current data
private bool nullFirst = false; //original Data null
private bool nullData = false; //current data null

private IntType()
{
}

private IntType(int initial)
{
first = initial;
data = initial;
}

public bool IsNull()
{
return nullData;
}

public bool IsFirstNull()
{
return nullFirst;
}

public void SetNull()
{
nullData = true;
data = 0;
}

public void SetFirstNull()
{
nullFirst = true;
first = 0;
}

// Properties

public int First
{
get { return first; }
set { first = value; }
}

public int Data
{
get { return data; }
set { data = value; nullData = false; }
}
} // end Class

************************************************** **

There are a bunch of classes - one for each datatype.

But I am getting an error trying to instantiate the object, but not sure
why?

Thanks,

Tom
Nov 17 '05 #1
3 1888
....because you said:

private IntType()
{
}

private IntType(int initial)
{
first = initial;
data = initial;
}

....which says, "There are only two ways to instantiate an object of
this class: one is a parameterless constructor, the other is by
supplying a single int value. However, this class itself is the only
thing that can create an instance of itself."

You marked the constructors "private", which means that they're
accessible only from within the IntType class itself. If you want other
classes to be able to create IntType objects directly, you'll have to
make at least one constructor "public".

Nov 17 '05 #2
tshad wrote:
I am getting a message for my objects that say:

testNulls.cs(13,33): error CS0122: 'FtsData.IntType.IntType()' is
inaccessible due to its protection level

I have a class calling objects out of another class, but same namespace.

This is the class that gets the error:
************************************************** ************
namespace FtsData
{
[Serializable]
public class TestNulls
{
private IntType testNullsID = new IntType(); <---------
Error line
...
The class that defines the IntType objects:
*************************************************
using System;

namespace FtsData
{
[Serializable]
public class IntType
{
private IntType() // change this to public if you need to invoke this constructor from another class.
{
}


Your parameterless constructor for IntType is private which means you
cannot invoke that constructor outside of the class. If you want to
call that constructor from a different class then you need to change its
protection level to public.
--
Tom Porterfield
Nov 17 '05 #3
That was it.

Not sure why I didn't see it.

Thanks,

Tom
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
...because you said:

private IntType()
{
}

private IntType(int initial)
{
first = initial;
data = initial;
}

...which says, "There are only two ways to instantiate an object of
this class: one is a parameterless constructor, the other is by
supplying a single int value. However, this class itself is the only
thing that can create an instance of itself."

You marked the constructors "private", which means that they're
accessible only from within the IntType class itself. If you want other
classes to be able to create IntType objects directly, you'll have to
make at least one constructor "public".

Nov 17 '05 #4

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

Similar topics

21
by: Sebastian Faust | last post by:
Hi, is a construction like the following possible: template<class view_model> class template_clase { protected: template_clase() {} virtual ~template_clase() {}
10
by: Bezalel Bareli | last post by:
I know I have seen some threads on the subject long time ago and it was using a virtual base class ... in short, what is the nicest way to implement the Java final class in c++ Thanks.
6
by: surrealtrauma | last post by:
i have a trouble about that: i want to ask user to enter the employee data (employee no., name, worked hour, etc.), but i dont know how to sort the data related to a particular employee as a...
7
by: spam | last post by:
The following code does not compile: class X {}; class Y : private X {}; class Z : public Y { public: Z(X&) {} // problem here
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
15
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
5
by: Amal P | last post by:
Dears, I have a question. class Data { }; class DisableDerive:virtual protected Data // A base class { private:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.