Reputation: 972
When tring to create a constructor for a class from the same class name. Why does it throws an error saying as follows:
" Error: 'StaveProcessor': member names cannot be the same as their enclosing type"
Code :
namespace ImageProcessing
{
class StaveProcessor
{
public Bitmap stave;
public StaveProcessor(Bitmap image) //constructor
{
stave = image;
}
}
}
How to solve this and create the constructor?
ps: Please consider my self not as an expert and excuse me for asking silly question if, and help me to learn and identify. Thank You
Upvotes: 1
Views: 4651
Reputation: 1249
@hirosht your code haven't got any error: see this page there was the same problem
Answer is(I think) you've declared your constructor with a type, like void or int or something else.
Upvotes: 1
Reputation: 15148
Well the code that you've provided has no issues in it (it compiles), the exception you're getting would show if you did something like the following:
class StaveProcessor
{
// can't have this method with this name (note the void, it's not a constructor)
public void StaveProcessor(Bitmap image)
{
stave = image;
}
}
Upvotes: 5