This is probably a C#-101 type question, but I've struck out on finding
an answer. I am setting up a class with a few overloaded constructors.
Inside those constructors, I would like to call the "default"
zero-argument constructor. The compiler gives me an error
"PC_StreamBuffe r is a type but is used like a variable". I've tried
adding "this." in front of references to PC_StreamBuffer (), but that
gives another compiler error. A simplified version of the class is as
follows:
class PC_StreamBuffer
{
private byte[] data;
public PC_StreamBuffer ()
{
length=0;
data=new byte[1000];
}
public PC_StreamBuffer (byte[] vals, int valsLength)
{
PC_StreamBuffer ();
this.Set(vals, valsLength);
}
public PC_StreamBuffer (byte[] vals)
{
PC_StreamBuffer ();
this.Set(vals);
}
<remainder of class methods removed>
}
Thanks,
Mike 3 3319
mblatch <mb*****@yahoo. com> wrote: This is probably a C#-101 type question, but I've struck out on finding an answer. I am setting up a class with a few overloaded constructors. Inside those constructors, I would like to call the "default" zero-argument constructor. The compiler gives me an error "PC_StreamBuffe r is a type but is used like a variable". I've tried adding "this." in front of references to PC_StreamBuffer (), but that gives another compiler error. A simplified version of the class is as follows:
<snip>
See http://www.pobox.com/~skeet/csharp/constructors.html
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
You call one constructor from another like this :
public PC_StreamBuffer ()
{
length=0;
data=new byte[1000];
}
public PC_StreamBuffer (byte[] vals, int valsLength) : this()
{
this.Set(vals, valsLength);
}
public PC_StreamBuffer (byte[] vals) : this()
{
this.Set(vals);
}
"mblatch" wrote: This is probably a C#-101 type question, but I've struck out on finding an answer. I am setting up a class with a few overloaded constructors. Inside those constructors, I would like to call the "default" zero-argument constructor. The compiler gives me an error "PC_StreamBuffe r is a type but is used like a variable". I've tried adding "this." in front of references to PC_StreamBuffer (), but that gives another compiler error. A simplified version of the class is as follows:
class PC_StreamBuffer { private byte[] data;
public PC_StreamBuffer () { length=0; data=new byte[1000]; }
public PC_StreamBuffer (byte[] vals, int valsLength) { PC_StreamBuffer (); this.Set(vals, valsLength); }
public PC_StreamBuffer (byte[] vals) { PC_StreamBuffer (); this.Set(vals); }
<remainder of class methods removed> }
Thanks, Mike
Thanks to you both for the quick fix and references. That worked. I
appreciate it.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brad Eck |
last post by:
"The only operators that cannot be overloaded
are :: (scope resolution), . (member selection), and .* (member
selection through pointer to function). Quoting from Stroustrup's 3rd
edition of _The C++ Programming Language_, section 11.2 (page 263),
these three operators 'take a name, rather than a value, as their
second operand and provide the primary means of referring to members.
Allowing them to be overloaded would lead to subtleties.'"...
|
by: maadhuu |
last post by:
hi
i wasnt to know the answer for the following.
now ,u can overload all the operators which are basically determined at
runtime (coz' of whch operators like sizeof())cannot be overloaded.
now my doubt is , if u have something like
p->a ....where p(say) is a pointer of a user defined type, then u can
overload this because p is determined at runtime ???is this right ???
also if "a" is an object of the some user defined class,
|
by: bahadir.balban |
last post by:
Hi,
What's the best way to implement an overloaded function in C? For
instance if you want to have generic print function for various
structures, my implementation would be with a case statement:
void print_structs(void * struct_argument, enum struct_type stype)
{
switch(stype) {
case STRUCT_TYPE_1:
|
by: John Davis |
last post by:
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.
Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement
Case 2: assignment operator
a = b
Just my observation. Please discuss.
|
by: Claudius |
last post by:
Hello,
I have written a class A with the access operator(int) overloaded by
a
A-const version which returns an int by value:
------------------------------------------------
#include <iostream>
using namespace std;
| |
by: Jack Daly |
last post by:
I've inherited some code which uses an undocumented feature of a
third-party vendor's library. Essentially, this vendor has kept the
details of an interface struct secret, but we can pass a pointer to
this struct to other vendor routines. The struct describes a complex
time-varying object, but it basically boils down to an integer, and
there are access routines to get to the current value of this integer.
My problem is:
1) Our code is...
|
by: mike3 |
last post by:
Hi.
Is this a good idea?:
<begin code>
/* Addition operator: += */
const BigFix &BigFix::operator+=(const BigFix &rhs)
{
ErrorType err;
int lhs_sign = sign, rhs_sign = rhs.sign;
|
by: abendstund |
last post by:
Hi,
I have the following code and trouble with ambiguity due to operator
overloading..
The code is also at http://paste.nn-d.de/441
snip>>
|
by: Peter Olcott |
last post by:
So far the only way that I found to do this was by making a
single global instance of the container class and providing
access to the contained class, through this single global
instance. Are there any other no-overhead ways that a
contained class can access its container?
The obvious choice of passing (a pointer or a reference to
the container) to the contained class is not a no-overhead
solution, it requires both memory and time. I am...
|
by: =?Utf-8?B?QWxhbWVsdQ==?= |
last post by:
I have overloaded a new operater for a class that returns void * and i have
created an object for that class in heap as below.
CMyClass *pMyClass = new CMyClass(); // Here though i haven't explicitly
casted void* to CMyClass, the compiler doesnt give error at all.
But in c++ for void* to specific type ptr , explicite cast is required. What
was the cause for the above statement to work?
Regards,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |