473,486 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Converting int to UserStruct on function call

464 Recognized Expert Contributor
I know that title isn't a great description so I apologize , but i don't know how to summaries it (probably also why i can't find any information online). I have a struct that contains 3 ints (used for coordinates) and i want a function to be able to pass in 3 ints and have the struct convert the 3 ints into a struct object.

Expand|Select|Wrap|Line Numbers
  1. struct  VectorCords
  2. {
  3.      int x, y, z;
  4. };
  5.  
  6. DoSomething (VectorCords VectorInfo) //Function that accepts VectorCords Struct
  7. {
  8.  . . . 
  9. }
  10.  
I want to be able from main or another function to pass in somthing like

DoSomething (5,7,12);
and have the object of VectorCords take those 3 ints and create an object of the struct. I know i can overload the function, but that seem like adding a lot of code for having the same values. Any ideas or any technical terms i can research to find the answer?
Sep 1 '07 #1
4 1514
Ganon11
3,652 Recognized Expert Specialist
This should be a fairly simple function. Just to make sure I understand you, you want a function DoSomething that will accept three int arguments and, from this data, create a VectorCords object, which I presume you will then return?

Well, I gather you can write the function header to properly accept the three ints. Then, you need to create a VectorCords pointer and allocate memory by using the new operator. Finally, you need to manually set the x, y, and z variables in the VectorCords object to your int arguments, and then return the pointer. You must do this with a pointer, because if you created an object normally within the function, it would be de-allocated after the function returned.
Sep 1 '07 #2
Studlyami
464 Recognized Expert Contributor
No i want the function DoSomething to accept a VectorCord object. What i want to happen is if for some reason the function gets passed 3 ints instead of a VectorCord i want those 3 int to be automatically assigned to x, y,z. Is there a way for this to happen without overloading the function.

ex

DoSomthing (VectorCordStuc ObjectOfStruct)
{
. . .
}

now during the program runnign
DoSomthing (VectorObject) //a vector cord stuct object
DoSomthing (2,6,8) // these int values get passed to do the same function
Sep 1 '07 #3
Ganon11
3,652 Recognized Expert Specialist
The only way you could solve this problem is to overload the function. Now, you could have the function accept three ints, make a temporary VectorCords object, and call the same function using the object, but the fact is you will have to overload the function.
Sep 2 '07 #4
Studlyami
464 Recognized Expert Contributor
Darn, oh well Thanks!
Sep 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3291
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never...
3
9982
by: rgarf | last post by:
I am converting a C++ application to C#, What in C# replaces the following C++ functions: overloaded opertaor= _ecvt(Math.Abs(val),14,&dec,&sign) ; //this function converts a double to a string...
9
2565
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
0
3818
by: ChrisWoodruff | last post by:
I have a C++ function in a COM object that I am trying to implement in VB.NET (the functionality, NOT the COM object, I want to remove the requirement for the COM DLL) I am an experienced VB...
2
2330
by: SM | last post by:
Hello group, we are converting a VB6 application, written by other people, for .NET Framework. Original application depends on a DLL written in standard C. The application communicates with an...
36
4411
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
13
4619
by: ppateel | last post by:
Hi, I am new to c++ and I am converting a c program to c++. I changed malloc call to new and I am getting an exception violation. Here is the relevant piece of code. Compiler vc++ 7.0 (.Net...
9
2534
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
5
1652
by: Peter Michaux | last post by:
There seem to be some options for converting the arguments object inside a function to an instance of Array. I'm curious if anyone has encountered any problems with any particular techniques for...
0
7105
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
5439
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,...
1
4870
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...
0
4564
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...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
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 ...
1
600
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
266
bsmnconsultancy
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...

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.