• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2254
  • Last Modified:

error C2061: syntax error : identifier 'ofstream', error C2061: syntax error : identifier 'GAGenome'

Hi guys, I am in need of some.. human input.

These are the relevant includes in my code:

#include "math.h"
#include "stdio.h"
#include "stdlib.h"
#include "assert.h"        
#include <iostream>        
#include <fstream>          
#include <iomanip>          
#include "conio.h"
#include "ga/ga.h"
#include "ga/GASimpleGA.h"  // Replaces the whole of the old population with the new
#include "ga/GASStateGA.h"  // Replaces worst genomes of old population with the
                            // newest genomes even when the old genomes were better than the new
#include "ga/GA1DArrayGenome.h" // An array of 'n' amount of weights 'w' (=genes)
#include "ga/GAScaling.h"
#include <string>
#include <sstream>
using namespace std;



Now, a few things that I have already done:

- A "command-prompt" program that I have already made compiles just fine and I was using the same compiler (VC++ 6.0).
- I tried both as <name.h> and "name.h"
- I did put the correct PATHS for VC++ to use to try and find the ga classes
- And besides, as i said before it works for my other program and I did the same things there!
- Finally, I have tried with including these both in the "filenamewin.cpp" and "filenamewindlg.cpp" and it still doesn't work :(((

Any helpful hints? I tried finding things on the web but answers about this error tell me what I already know - most of the questions were in this forum, mind you ;)

Thanks, i require an answer really urgently :( - hence the higher points award

0
Gene_Cyp
Asked:
Gene_Cyp
  • 13
  • 8
1 Solution
 
nonubikCommented:
You need to post the code where you get the compile errors, too.
0
 
Gene_CypAuthor Commented:
One mroe thing, I have just noticed:

The only ones that seem to have a compilation error are the ones that use a reference ("&"):

openOutputFile(ofstream &outfile, string filename)

and

all the functions that use GAGenome&

eg:

Initializer(GAGenome&)

0
 
Gene_CypAuthor Commented:
The compile errors point to all the functions that atleast one of their parameters is either: "ofstream&" or "GAGenome&"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
nonubikCommented:
You need to include <fstream.h> and <GAGenome.h> (the header for the GAGenome) in every file that you use them.
The errors do not have any link with the fact that you use '&'.
0
 
Gene_CypAuthor Commented:
Both of those are already included

fstream is included as:


#include <fstream>

I tried the ".h" version as well and it didn't work.
0
 
nonubikCommented:
Right, it's <fstream>, not <fstream.h>

Pleas post some code (like code with compile errors and included headre files)

#include ...
..........
openOutputFile(ofstream &outfile, string filename) <- error line
//some more lines
0
 
Gene_CypAuthor Commented:
Yeah, you are right to point out the "&" is not related... but I noticed it and thought I'd mention it, just in case.

But something you said about every file that uses them -> that solved the problem. I added them in the main header file as well and they work now... thanks.

It was frustrating knowing that it had to do with the include files but not knowing how to fix it.

0
 
nonubikCommented:
Glad to be helpfull.
0
 
Gene_CypAuthor Commented:
Here's something else you might want to help me with:

I got this error:

Linking...
MyClassName.obj : error LNK2001: unresolved external symbol "float __cdecl ran2(void)" (?ran2@@YAMXZ)

0
 
nonubikCommented:
If ran2 is an imported symbol, you must link against the .lib from where it is exported.
0
 
Gene_CypAuthor Commented:
I tracked it down to two other headers:

gaconfig.h
garandom.h

Link against the library? ?

0
 
Gene_CypAuthor Commented:
This must be the line causing the problem:

inline float GARandomFloat(float low, float high){
  float val=high-low; val*=_GA_RND(); return val+low;
}

I call GArandomFloat in my class.. again this error never came up , with the SAME compiler and the same "included files" in my "dos version".
0
 
nonubikCommented:
for ran2 link error, include garandom.c in your project file
0
 
Gene_CypAuthor Commented:
it's already linked
0
 
nonubikCommented:
so what's your error now?
0
 
Gene_CypAuthor Commented:
that's the error i get, despite the fact that it's linked.. it was linked already
0
 
Gene_CypAuthor Commented:
If I add the actual .cpp file instead of its header I get "already defined" errors
0
 
nonubikCommented:
Where do you get allready defined?
0
 
Gene_CypAuthor Commented:
Do you have icq or some other form of messenger?

My ICQ is 4506289 -> much faster that way and once the problem is resolved we can always psot the answer here for others that happen to be reading it...
0
 
Gene_CypAuthor Commented:
Linking...
TestGALibWinDlg.obj : error LNK2005: "char const * __cdecl GAGetRNG(void)" (?GAGetRNG@@YAPBDXZ) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "unsigned int __cdecl GAGetRandomSeed(void)" (?GAGetRandomSeed@@YAIXZ) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "void __cdecl GARandomSeed(unsigned int)" (?GARandomSeed@@YAXI@Z) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "void __cdecl GAResetRNG(unsigned int)" (?GAResetRNG@@YAXI@Z) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "double __cdecl GAUnitGaussian(void)" (?GAUnitGaussian@@YANXZ) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "int __cdecl GARandomBit(void)" (?GARandomBit@@YAHXZ) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "void __cdecl sran2(unsigned int)" (?sran2@@YAXI@Z) already defined in TestGALibWin.obj
TestGALibWinDlg.obj : error LNK2005: "float __cdecl ran2(void)" (?ran2@@YAMXZ) already defined in TestGALibWin.obj
0
 
Gene_CypAuthor Commented:
Answer: had to add the definition of the RAN2 function onto my own .cpp class
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 13
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now