Thread: help me understand this line of code

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    106

    help me understand this line of code

    How do you interpret this line :

    Code:
    dataset_loader (const string& filename) : hdf5_file(filename, H5F_ACC_RDONLY), datasets() {}
    ...and how would you use it? Thanks in advance.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It looks like a line of a constructor for a class called dataset_loader, which takes a string (filename), then calls the base-class constructor with:
    hdf5_file(filename, H5F_ACC_RDONLY), datasets()


    How you would use that would be something like:
    Code:
    ... 
      dataset_loader ds("mydatafile.h5f");
    ...
    How you would further use the dataset_loader class, you haven't given any information to tell, so I can't even guess.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    dataset_loader (const string& filename) : hdf5_file(filename, H5F_ACC_RDONLY), datasets() {}
    Actually, from what I see, it initializes two things (see the red). Perhaps one constructor and a default initialization of a member object?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Code:
    public:
      static void Init () { Exception::dontPrint(); }
      dataset_loader (const string& filename) : hdf5_file(filename, H5F_ACC_RDONLY), datasets() {}
      ~dataset_loader () {hdf5_file.close();
       }
    
      const dataset_buf& read_data_set (const string& dataname) {
    I should be able to access objects , such as, "mybuf(x,y,z)" . read_data_set returns a reference to dataset_buf. I am confused about which dataset_buf to use, as doing "dataset_buf somebuffer" is valid. This code is in a header file.

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by Elysia View Post
    Code:
    dataset_loader (const string& filename) : hdf5_file(filename, H5F_ACC_RDONLY), datasets() {}
    Actually, from what I see, it initializes two things (see the red). Perhaps one constructor and a default initialization of a member object?
    Could it be an initialization parameter?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by elninio View Post
    Code:
    public:
      static void Init () { Exception::dontPrint(); }
      dataset_loader (const string& filename) : hdf5_file(filename, H5F_ACC_RDONLY), datasets() {}
      ~dataset_loader () {hdf5_file.close();
       }
    
      const dataset_buf& read_data_set (const string& dataname) {
    I should be able to access objects , such as, "mybuf(x,y,z)" . read_data_set returns a reference to dataset_buf. I am confused about which dataset_buf to use, as doing "dataset_buf somebuffer" is valid. This code is in a header file.
    It is pretty hard to guess how a class should be used without understanding the full class hierarchy of all classes that are involved in the subsystem.

    Code:
    dataset_buf somebuffer = read_data_set("somename");
    is valid code, but it doesn't mean that's CORRECT code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    my code :

    Code:
    int main(int argc, char* argv[]){
    	argc--;
    	if ( argc < 1){
    		cout << "Usage:" << endl << "h5inspect file.h5" << endl;
    		return 0;
    	}
    	//iterate *.h5 in ascending order
    	for (int count = 1; count <= argc; count ++){ 
    		
    		char iterchar; 
    		const string filename = argv[count]; 
    		cout << "HDF5 \"" << filename << "\" { "<< endl;
    		dataset_loader dset( filename); 
    	
    		cout << "GROUP \"/\" {" << endl;
    		cout << "   DATASET \"";
    		
    		while (iterchar != '\"'){
    			iterchar = getchar();
    			if(iterchar != '\"') putchar (iterchar);
    		} 
    		
    		cout << endl << endl << iterchar << endl << endl;
    		//cout << "\" {" << endl;		
    		
    		dataset_buf& read_data_set(string(iterchar));
    		cout << dset << "pie";
    		cout << endl << endl << endl;
    	}
    	return 0;
    My errors:

    Code:
    h5inspect.cpp: In function 'int main(int, char**)':
    h5inspect.cpp:33: error: no match for 'operator<<' in 'std::cout << dset'
    /usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:78: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:90: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/lib/gcc/i486-slackware-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:241: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
     etc..

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are trying to output "dset", but you (or anyone else) haven't told the compiler how a dset should be output.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jun 2008
    Posts
    106
    Quote Originally Posted by matsp View Post
    You are trying to output "dset", but you (or anyone else) haven't told the compiler how a dset should be output.


    --
    Mats

    i have << operator overloading

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Obviously it isn't working, however.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C code line, pointer declaration
    By Dedalus in forum C Programming
    Replies: 2
    Last Post: 06-10-2009, 04:34 AM
  2. help again with scrolling without wrapping
    By Dukefrukem in forum C Programming
    Replies: 8
    Last Post: 09-21-2007, 12:48 PM
  3. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM