Need xome help on template calss library in C#

G

Guest

Sir,

I am facing an certain problem , i am trying to convert a piece of code in
VisaualC# .hope some body will helpme out about this how can it be done
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class grip: public wait<grip>

{

public:

int make[5];

int rate;

grip(int x, int y, int s, int d, int t, int v) {

make [0]=x; make [1]=y; make [2]=s; make [3]=d; make [4]=t;

rate=v;

new=NULL;

}

};

// Class used to store detections

class deceit : public wait < deceit >

{

public:

int x, y, s, orient, profile;

double output;

deceit (int xx, int yy, int ss, double o, int dir, int pr=0) {

x=xx; y=yy; s=ss; output=o; orient=dir; profile=pr;

}

};

template <class T>

class wait

{

public:

T *old, *new;

wait();

~wait();

};

How can i convert this code to visual c#.

waiting for reply eagerly.

Regards
Naveen
 
O

Oliver Sturm

Naveen said:
I am facing an certain problem , i am trying to convert a piece of code in
VisaualC# .hope some body will helpme out about this how can it be done.

Assuming you are using C# 2.0, the following is a rough translation. If
you are on C# 1, templates are not supported and you'd have to implement
the whole hierarchy differently.

public class Wait<T> {
public T old, new;
}

public class Deceit : Wait<Deceit> {
public int x, y, s, orient, profile;
public double output;

public Deceit(int xx, int yy, int ss, double o, int dir, int pr) {
x = xx; y = yy; s = ss; output = o; orient = dir; profile = pr;
}

public Deceit(int xx, int yy, int ss, double o, int dir) :
this(xx, yy, ss, o, dir, 0) {
}
}

public class Grip: Wait<Grip> {
public int[] make = new int[5];
public int rate;

public Grip(int x, int y, int s, int d, int t, int v) {
make[0] = x; make[1] = y; make[2] = s; make[3] = d; make[4] = t;
rate = v;
new = null;
}
}

Now let me mention that this is horrible C# code... the least thing that
should be done is use properties instead of the public fields, and use
proper names for the variables and constructor parameters.


Oliver Sturm
 
G

Guest

hi,

i was trying to write a c# code , were i need to pass ponitrtas an functin
argument . but when ever i am trying to do it i am getting error

"Cannot take the address or size of a variable of a managed type"

I am writing a piece of code were in which i am getting it can ayone help me
to remove it.
//////////////////////////////////////////////////////////////////////////////////////////////////////////


public unsafe class Node
{
public unsafe Node *pr;
public unsafe Node *ne;
}
***********************************************************
public unsafeclass Element : Node
{

public unsafe Element *fist;
public unsafe Element *lst;
public int length;

}
public unsafe void adBefore(Element *ptr, Element *pce)
{

{
ptr->pr=pce->pr;
if (pce->pr!=null)
pce->pr->ne=ptr; else
fist=ptr;
pce->pr=ptr;
ptr->ne=pce;
length++;
}
}


};
////////////////////////////////////////////////////////////////////////////////////////////////////

Hope anyone will provide a soln to me regarding this problem.

waiting for reply eagerly.

Regards

Naveen
 
M

Mattias Sjögren

i was trying to write a c# code , were i need to pass ponitrtas an functin
argument . but when ever i am trying to do it i am getting error

Why do you feel you have to use pointers and unsafe code here?

You can't take the address of a reference type variable such as Node.



Mattias
 
G

Guest

wht is an alternative for it, is there any alternative for it, how can i
write down this piece of code in c# correctly.
 
M

Mattias Sjögren

wht is an alternative for it, is there any alternative for it

Plain references.

public class Node
{
public Node pr;
public Node ne;
}

public class Element : Node
{
public Element fist;
public Element lst;
public int length;
}

and replace all -> with . in the code.




Mattias
 
G

Guest

hi,

I have already done that and code is compiling without erros, but will the
the code work, as i am building the dll.


2. i also found out that if i have already an dll made , i cn use it in
..net.i havealready dll made in VC++ and evc++4.2 , can i use them in my .net
code?

Regards

Naveen
 
G

Guest

hi,

the piece if code i had sent is the code of linked list, will the code work
without using pointers.

regards

naveen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top