[sclug] C++ Question

Tim Sutton suttont at onetel.net.uk
Sat Oct 25 09:05:44 UTC 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

Any of you C++ gurus able to tell me what is wrong with this? I am trying to 
get the alterrnate constructor to work that takes a string for the filename 
rather than the filename.

When compiling I get the following:

aps02ts at pc2-rdng3-4-cust67:~/dev/cpp/csm_dataprep/csm_dataprep$ g++ 
filewriter.cpp
In file included from filewriter.cpp:18:
filewriter.h:33: parse error before `,' token
filewriter.cpp:31: prototype for 
`FileWriter::FileWriter(std::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, FileWriter::FileTypeEnum)' does not match any in 
class `FileWriter'
filewriter.h:27: candidates are: FileWriter::FileWriter(const FileWriter&)
filewriter.cpp:21:                 FileWriter::FileWriter(const char*, 
FileWriter::FileTypeEnum)

But I dont see what the problem around the comma on line 33 is :-(

Thanks

Tim

- ---------------------------------------------------------------------------
filewriter.h:
- ---------------------------------------------------------------------------
#ifndef FILEWRITER_H
#define FILEWRITER_H

#include <stdio.h>
#include <string.h>
/**A FileWriter is used to store the results of the climate data processor in 
a persistant manner.
  *@author Tim Sutton
  */

class FileWriter {
public:
    enum FileTypeEnum { CSM_MATLAB , CSM_OCTAVE ,  GARP ,  ESRI_ASCII ,  PLAIN 
};
  /** constructor */
	FileWriter(const char *theFileName, FileWriter::FileTypeEnum theFileFormat);
  /** Alternate constructor that takes a string for the filename rather than a 
char array. */
   FileWriter(const std::string theFileNameString, FileWriter::FileTypeEnum 
theFileFormat);
  /** destrctor */
  ~FileWriter();
  /** Write a float element to the output file. */
  bool writeElement(float theElementFloat);

private:
  /**  The FILE handle containing our output data matrix. */
  FILE *filePointer;  
};

#endif

- ---------------------------------------------------------------------------
filewriter.cpp :
- ---------------------------------------------------------------------------

#include "filewriter.h"
#include <iostream>

FileWriter::FileWriter(const char *theFileNameChar, FileWriter::FileTypeEnum 
theFileFormat){

    if ((filePointer=fopen(theFileNameChar,"wb"))==NULL)  //open in binary 
mode
  {
    //cout << "Cannot open file : " << theFileNameChar << endl;
  }
  //cout << "Opened file : " << theFileNameChar << " successfully." << endl;
}

/** Alternate constructor that takes a string for the filename rather than a 
char array. */
 FileWriter::FileWriter(const std::string theFileNameString, 
FileWriter::FileTypeEnum theFileFormat){
}

FileWriter::~FileWriter(){
}

/** Write a float element to the output file. */
bool FileWriter::writeElement(float theElementFloat){
  fprintf ( filePointer, "%f ",theElementFloat);
}



- -- 
Get my public keys from:

http://tim.suttonfamily.co.uk/modules.php?name=Content&pa=showpage&pid=2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+8WWuWvXTJUo0BDoRAiGKAJ0W3SiQiZ0PSqd/LkztwHw/OSpn5gCgpjt5
JyHQOQ3xJDN1FhueomnQ3Dw=
=/ySL
-----END PGP SIGNATURE-----




More information about the Sclug mailing list