473,397 Members | 2,099 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,397 software developers and data experts.

Need xome help on template calss library in C#

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
Nov 17 '05 #1
7 1283
Naveen koul wrote:
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
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2


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
Nov 17 '05 #3
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #4

wht is an alternative for it, is there any alternative for it, how can i
write down this piece of code in c# correctly.
"Mattias Sjögren" wrote:
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 17 '05 #5
>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #6


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
Nov 17 '05 #7


hi,

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

regards

naveen
Nov 17 '05 #8

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

Similar topics

5
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl...
11
by: Matt | last post by:
I'm posting this question for one of my developers who's not quite as newsgroup-savvy. Any suggestions? The question follows, along with relevant source code. -Matt I have a templated...
22
by: macAWM | last post by:
Hi list, First let me explain that my background is in Java and I am quite spoiled to its niceties (read "less ambiguous nature"). Anyway to my problems. 1. I want to write my own library for...
0
by: Robbie Hatley | last post by:
I'd always thougth that a C++ compiler/linker should be able to instantiate a template in mulitple places (say, in two different translation units), even using the same template parameters so that...
1
by: Robbie Hatley | last post by:
I asked about this yesterday, but no one bit. So I'll ask again. I can be a persistant cuss. :-) I ran into a problem a few days ago when I added a couple of template functions to one of my...
5
by: aaragon | last post by:
Hello everybody, I appreciate your taking the time to take a look at this example. I need some help to start the design of an application. To that purpose I'm using policy-based design. The...
19
by: n.torrey.pines | last post by:
I have the following tree definition: template<typename T> struct tree { T first; vector<tree<T second; // branches }; which compiles successfully. What I'd like to do though is to use...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
11
by: Juha Nieminen | last post by:
I'm writing an STL-style data container, and this problem is puzzling me. The following code should demonstrate the problem: //---------------------------------------------------------- #include...
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: 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:
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.