Solved

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

Posted on 2004-08-02
21
2,155 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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
 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 86
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 94
scoreUp challenge 14 62
changeXy challenge 13 82
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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

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