LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2003, 10:05 PM   #1
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Rep: Reputation: 15
c++ structure-array question


Hiya,

Say I had a data structure containing 3 floats, such as:

struct threefloats
{
float x, y, z;
} float3f;

and I had a function which operates on an array of floats, such as:

void foo(float xyz[3]);

Is there anyway that I could modify the threefloats structure so as I could call foo with an argument of type threefloats? I know that I could make it return float by adding:

operator float()

to structure, but what about casting threefloats to an array such that x, y, and z in the threefloats structure gets put into the array for foo() to operate on.

Thanks,
deveraux83
 
Old 01-01-2004, 06:50 AM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Just cast a pointer to the structure to the type (float *), and then pass the resulting value as the argument to the function.

Alex
 
Old 01-01-2004, 08:55 AM   #3
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Original Poster
Rep: Reputation: 15
Wink

Yup, that did it ..thanks LM!!

deveraux83
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
directory structure question bmorency Linux - Newbie 1 10-27-2005 04:31 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
File system/structure question ashley75 Linux - General 1 05-17-2005 09:02 PM
/home directory structure question Dswissmiss Linux - General 2 09-29-2004 11:54 AM
structure question Lostman Linux - Newbie 1 11-04-2003 02:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration