Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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.

Old 01-01-2004, 07:50 AM   #2
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.

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

Original Poster
Rep: Reputation: 15

Yup, that did it ..thanks LM!!



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 > Forums > Non-*NIX Forums > Programming

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

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