Solved

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

Posted on 2004-08-02
21
2,141 Views
Last Modified: 2013-11-20
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
Comment
Question by:Gene_Cyp
  • 13
  • 8
21 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 11691841
You need to post the code where you get the compile errors, too.
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692050
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
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692058
The compile errors point to all the functions that atleast one of their parameters is either: "ofstream&" or "GAGenome&"
0
 
LVL 16

Accepted Solution

by:
nonubik earned 350 total points
ID: 11692118
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
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692126
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
 
LVL 16

Expert Comment

by:nonubik
ID: 11692136
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
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692205
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
 
LVL 16

Expert Comment

by:nonubik
ID: 11692237
Glad to be helpfull.
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692422
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
 
LVL 16

Expert Comment

by:nonubik
ID: 11692459
If ran2 is an imported symbol, you must link against the .lib from where it is exported.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692504
I tracked it down to two other headers:

gaconfig.h
garandom.h

Link against the library? ?

0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692532
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
 
LVL 16

Expert Comment

by:nonubik
ID: 11692565
for ran2 link error, include garandom.c in your project file
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11692637
it's already linked
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11692649
so what's your error now?
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11694148
that's the error i get, despite the fact that it's linked.. it was linked already
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11701199
If I add the actual .cpp file instead of its header I get "already defined" errors
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11701449
Where do you get allready defined?
0
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11701505
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
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11701525
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
 
LVL 7

Author Comment

by:Gene_Cyp
ID: 11701814
Answer: had to add the definition of the RAN2 function onto my own .cpp class
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 127
Include multiple hostnames in this command? 3 52
sameEnds challenge 3 106
wordappend challenge 8 85
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now