473,387 Members | 1,574 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.

Strange error with constructors

Hi,

If I try to compile the code below, I get a weird error that seems to be
related with hte constructors.

-------------------------------------
class Action : System.Object
{
Object _something;

public Action( Object something )
{
_something = something;
}

public virtual void go()
{
Console.WriteLine(_something.ToString());
}
}
class Prueba : Action
{
public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}

--------------------------------------------

The error says something like: no overload for the method Action requires 0
arguments.

What the Hell does this mean? O:-)

Thanks
Nov 16 '05 #1
4 1175
When inheriting a base class you effectivly will cause the CLR to create an
instance of that base class.

Since your base class only have one constructor, and that constructor needs
a parameter. The CLR cannot create the base object.

To make this work, you need to supply the parameter to the base class from
the sub class.

Btw, what does Prueba mean ;)

<code>
class Prueba : Action
{
public Prueba() : base(null)
{}

public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}
</code>

--
Patrik Löwendahl [C# MVP]
www.cshrp.net - "Elegant code by witty programmers"

"Fernando Rodríguez" <fe*******************@fernando-rodriguez.com> wrote in
message news:73********************************@4ax.com...
Hi,

If I try to compile the code below, I get a weird error that seems to be
related with hte constructors.

-------------------------------------
class Action : System.Object
{
Object _something;

public Action( Object something )
{
_something = something;
}

public virtual void go()
{
Console.WriteLine(_something.ToString());
}
}
class Prueba : Action
{
public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}

--------------------------------------------

The error says something like: no overload for the method Action requires
0
arguments.

What the Hell does this mean? O:-)

Thanks

Nov 16 '05 #2
On Sun, 10 Oct 2004 19:02:18 +0200, "Patrik Löwendahl [C# MVP]"
<pa**************@csharpsweden.com> wrote:
When inheriting a base class you effectivly will cause the CLR to create an
instance of that base class.

Since your base class only have one constructor, and that constructor needs
a parameter. The CLR cannot create the base object.

To make this work, you need to supply the parameter to the base class from
the sub class.
OK, I got it now. :-)
Btw, what does Prueba mean ;)


Test. :-)
Nov 16 '05 #3
Fernando Rodríguez <fe*******************@fernando-rodriguez.com>
wrote:
If I try to compile the code below, I get a weird error that seems to be
related with hte constructors.


See http://www.pobox.com/~skeet/csharp/constructors.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
I think that's Spanish for 'test'

On Sun, 10 Oct 2004 19:02:18 +0200, "Patrik Löwendahl [C# MVP]"
<pa**************@csharpsweden.com> wrote:
When inheriting a base class you effectivly will cause the CLR to create an
instance of that base class.

Since your base class only have one constructor, and that constructor needs
a parameter. The CLR cannot create the base object.

To make this work, you need to supply the parameter to the base class from
the sub class.

Btw, what does Prueba mean ;)

<code>
class Prueba : Action
{
public Prueba() : base(null)
{}

public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}
</code>


Nov 16 '05 #5

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

Similar topics

8
by: Shane Groff | last post by:
I know this is a recurring discussion (I've spent the last 3 days reading through threads on the topic), but I feel compelled to start it up again. After reading through the existing threads, I...
9
by: Gutek | last post by:
Hello all, I have run into the following problem with virtual destructor. I have following classes: class A { public: double* p; A(unsigned int s=0) : { p = new double ; }
8
by: grundmann | last post by:
Hello, i got a strange compiler error. When compiling the following: // forward declarations typedef AvlTree<LineSegment,LineSegmentComperator> LSTree; void handleEventPoint (const...
4
by: Valeriu Catina | last post by:
Hi, g++ gives the next error messages test.cpp: In function 'int main()': test.cpp:53: error: invalid conversion from 'int' to 'SmallVectorNoInit (*)()' test.cpp:53: error: initializing...
28
by: charlie | last post by:
Hi, I found an article on informit.com that talks about C++ casts http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1 The strange thing is the author says the following...
12
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
23
by: mike3 | last post by:
Hi. I seem to have made some progress on finding that bug in my program. I deactivated everything in the bignum package that was used except for the returning of BigFloat objects. I even...
0
by: MR | last post by:
I have written a wrapper for an unmanaged class that is in a .LIB file The two constructors of the new managed class look like this: CThrShMemLibWrapper::CThrShMemLibWrapper() { } ...
1
by: gozlemci | last post by:
Hi everybody; During my coding, I have encountered a problem.I appreciate if anybody answer it. Here is the simplified code: //Header5.h #pragma once #include <string> using namespace std;
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:
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.