?
Solved

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

Posted on 2004-08-02
21
Medium Priority
?
2,215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 16

Accepted Solution

by:
nonubik earned 1400 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
 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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