LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 11: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, 07: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, 09: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:31 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 05:23 AM
File system/structure question ashley75 Linux - General 1 05-17-2005 10:02 PM
/home directory structure question Dswissmiss Linux - General 2 09-29-2004 12:54 PM
structure question Lostman Linux - Newbie 1 11-04-2003 03:01 AM

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

All times are GMT -5. The time now is 03:51 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration