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

Get Reference

I have a function
private static TypeA GetA()
{...}

Now I need to pass object that I get from GetA() as a
reference to a base class constructor. How to do it?

I tried doing
public MyClass() :
base(GetA())
{
}
but the compiler complains
"Argument '1': cannot convert from 'TypeA' to 'ref TypeA'
"

Please help.
Thanks,
Tatyana
Nov 15 '05 #1
5 1606
your example is far from complete, but i can give you a suggestion.
try
public MyClass() : base(ref GetA())
{

}

If that won't work, then you are pretty much out of luck, i don't know how
well ref works when it comes to method calls.
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
I have a function
private static TypeA GetA()
{...}

Now I need to pass object that I get from GetA() as a
reference to a base class constructor. How to do it?

I tried doing
public MyClass() :
base(GetA())
{
}
but the compiler complains
"Argument '1': cannot convert from 'TypeA' to 'ref TypeA'
"

Please help.
Thanks,
Tatyana

Nov 15 '05 #2
It doesn't work. I get "A ref or out argument must be an
lvalue" when I try to do it.

I'm pretty sure that there should be some way to do it.
Otherwise I'm not able to construct the object because
base class doesn't have constructor without arguments.

Any other idea?

Thanks!
-----Original Message-----
your example is far from complete, but i can give you a suggestion.try
public MyClass() : base(ref GetA())
{

}

If that won't work, then you are pretty much out of luck, i don't know howwell ref works when it comes to method calls.
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
I have a function
private static TypeA GetA()
{...}

Now I need to pass object that I get from GetA() as a
reference to a base class constructor. How to do it?

I tried doing
public MyClass() :
base(GetA())
{
}
but the compiler complains
"Argument '1': cannot convert from 'TypeA' to 'ref TypeA' "

Please help.
Thanks,
Tatyana

.

Nov 15 '05 #3
Well, that is a nasty spot(and a not very well designed base class, but
thats another matter)

the only thing i could think of is

public class MyClass : Base
{

public MyClass() : Base(ref internalStaticRef)
{

}

internal static TypeA internalStaticRef = new TypeA();
}

if that works, i'd contact the assembly maker and suggest they reconsider
their design, if you can.
"Tatyana" <m_*****@mail.ru> wrote in message
news:06****************************@phx.gbl...
I can not change the base class.It is defined in external
assembly and I don't have control over it.
-----Original Message-----
Does the base class HAVE to have a ref argument?
Your only other possibility is a internal static field,

I just did some
reading and properties cannot be passed as ref either.
Did you design the base, or are are you stuck wtih it?
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
It doesn't work. I get "A ref or out argument must be an lvalue" when I try to do it.

I'm pretty sure that there should be some way to do it.
Otherwise I'm not able to construct the object because
base class doesn't have constructor without arguments.

Any other idea?

Thanks!

>-----Original Message-----
>your example is far from complete, but i can give you a suggestion.
>try
>public MyClass() : base(ref GetA())
>{
>
>}
>
>If that won't work, then you are pretty much out of
luck, i don't know how
>well ref works when it comes to method calls.
>"Tatyana" <m_*****@mail.ru> wrote in message
>news:05****************************@phx.gbl...
>> I have a function
>> private static TypeA GetA()
>> {...}
>>
>> Now I need to pass object that I get from GetA() as a >> reference to a base class constructor. How to do it?
>>
>> I tried doing
>> public MyClass() :
>> base(GetA())
>> {
>> }
>> but the compiler complains
>> "Argument '1': cannot convert from 'TypeA' to 'ref
TypeA'
>> "
>>
>> Please help.
>> Thanks,
>> Tatyana
>
>
>.
>

.

Nov 15 '05 #4
I DID IT!
I created one more constructor
private MyClass(TypeA a) :
base(ref a)
{
}

and changed existing constructor to
public MyClass():
this(GetA())
{
}

Daniel, thanks for you help!
Let me know if you find better solution :)

Tatyana
-----Original Message-----
I can not change the base class.It is defined in externalassembly and I don't have control over it.
-----Original Message-----
Does the base class HAVE to have a ref argument?
Your only other possibility is a internal static field,I just did some
reading and properties cannot be passed as ref either.
Did you design the base, or are are you stuck wtih it?
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
It doesn't work. I get "A ref or out argument must bean lvalue" when I try to do it.

I'm pretty sure that there should be some way to do it. Otherwise I'm not able to construct the object because
base class doesn't have constructor without arguments.

Any other idea?

Thanks!

>-----Original Message-----
>your example is far from complete, but i can give youa
suggestion.
>try
>public MyClass() : base(ref GetA())
>{
>
>}
>
>If that won't work, then you are pretty much out of
luck, i don't know how
>well ref works when it comes to method calls.
>"Tatyana" <m_*****@mail.ru> wrote in message
>news:05****************************@phx.gbl...
>> I have a function
>> private static TypeA GetA()
>> {...}
>>
>> Now I need to pass object that I get from GetA()
as
a >> reference to a base class constructor. How to do

it? >>
>> I tried doing
>> public MyClass() :
>> base(GetA())
>> {
>> }
>> but the compiler complains
>> "Argument '1': cannot convert from 'TypeA' to 'ref
TypeA'
>> "
>>
>> Please help.
>> Thanks,
>> Tatyana
>
>
>.
>

.

.

Nov 15 '05 #5
actually, i was just going to come back and suggest this same solution, but
you beat me to it, ;)
Still, i'd complain about that lacking design in the assembly if possible,
but your welcome
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
I DID IT!
I created one more constructor
private MyClass(TypeA a) :
base(ref a)
{
}

and changed existing constructor to
public MyClass():
this(GetA())
{
}

Daniel, thanks for you help!
Let me know if you find better solution :)

Tatyana
-----Original Message-----
I can not change the base class.It is defined in

external
assembly and I don't have control over it.
-----Original Message-----
Does the base class HAVE to have a ref argument?
Your only other possibility is a internal static field,

I just did some
reading and properties cannot be passed as ref either.
Did you design the base, or are are you stuck wtih it?
"Tatyana" <m_*****@mail.ru> wrote in message
news:05****************************@phx.gbl...
It doesn't work. I get "A ref or out argument must be

an
lvalue" when I try to do it.

I'm pretty sure that there should be some way to do it. Otherwise I'm not able to construct the object because
base class doesn't have constructor without arguments.

Any other idea?

Thanks!

>-----Original Message-----
>your example is far from complete, but i can give you
a
suggestion.
>try
>public MyClass() : base(ref GetA())
>{
>
>}
>
>If that won't work, then you are pretty much out of
luck, i don't know how
>well ref works when it comes to method calls.
>"Tatyana" <m_*****@mail.ru> wrote in message
>news:05****************************@phx.gbl...
>> I have a function
>> private static TypeA GetA()
>> {...}
>>
>> Now I need to pass object that I get from GetA()

as
a
>> reference to a base class constructor. How to do

it? >>
>> I tried doing
>> public MyClass() :
>> base(GetA())
>> {
>> }
>> but the compiler complains
>> "Argument '1': cannot convert from 'TypeA' to 'ref
TypeA'
>> "
>>
>> Please help.
>> Thanks,
>> Tatyana
>
>
>.
>
.

.

Nov 15 '05 #6

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

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
11
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
41
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
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: 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
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
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
marktang
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,...
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.