How to copy a C struct to a C++ class?

This is a discussion on How to copy a C struct to a C++ class? within the C++ Programming forums, part of the General Programming Boards category; C++ Witch: I found this in a google search for how to copy a C struct to a C++ class. ...

  1. #1
    Banned
    Join Date
    Feb 2009
    Posts
    1

    How to copy a C struct to a C++ class?

    C++ Witch:

    I found this in a google search for how to copy a C struct to a C++ class.

    This seems closer to what I need to know than anything I have found.

    Explaination:

    I have a library (ancio, from PNNL, written by Jason Christy) that will read a netCDF file into a C struct. It is general code that will read any netCDF file into a C struct named data. I do not understand C well enought to only copy those parts (of the program and the header file).

    I want to then copy that C struct, include the contents, into a C++ class. I want to do that so that I can output the C struct contents into a ROOT Ttree (from CERN). The Ttree is written to accept C structs, but the over head of offsets, etc is automatically determine from a C++ class.

    I have compiled the ancio library using C++ (very few modifications were required, mostly () , and moving a definition). So using C++ I want to include the headers I need, that is ROOT includes for creating Ttrees, the netCDF header, the ancio.h, and using the small amount of C code that I have been able to write (using a few printf(some pointer to the C data struct) convincing myself that I have opened the netCDF file, and read its contents into the data struct.
    Code:
    It will be extern "C" {
    my code to open the netCDF file, create *dataP, and then 
    }  //end extern C
    
    C++ code here to create, open and write to a Ttree //examples abound on the internet
    
    the copy *dataP to class data
    
    then convert netCDF storage types to Ttree types
    then close the file.
    So that is what I want to do. I have read every available C++ book I can find at Borders
    and searched the internet, and nothing seems to have the answer.

    You seem to be closer to it here than I have been.

    Thanking you in advance.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    This thread was split from copy struct contents by bandal27.

    EDIT:
    I changed my mind about placing this in the C programming forum as this seems more towards the C++ side of things.
    Last edited by laserlight; 02-21-2009 at 01:14 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  2. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. Bi-Directional Linked Lists
    By Thantos in forum C Programming
    Replies: 6
    Last Post: 12-11-2003, 09:24 AM
  5. copy struct to class
    By guda in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2003, 09:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21