I am getting the following errors when compiling the below code:
3>c:hedgehedgehedgeAisTarget.h(22) : error C2059: syntax error : 'constant'
3>c:hedgehedgehedgeAisTarget.h(22) : error C2238: unexpected token(s) preceding ';'
#if !defined(AisTarget_h)
#define AisTarget_h
#include "GeneralAviationItems.h"
#include <string>
namespace HEDGE {
using namespace GeneralAviation;
class AisTarget : public WaypointLatLon {
public:
static const int NO_DATA = -1000; //here is the error
};
} // end namespace HEDGE
#endif
asked Aug 2, 2012 at 16:41
3
It is likely that NO_DATA
is already defined as a macro elsewhere, and so it is expanding into something that does not agree with the compiler’s notion of a variable name. Try re-naming NO_DATA
to something else.
If there were no such conflict, the code as it were would compile fine, as demonstrated here.
answered Aug 2, 2012 at 16:45
jxhjxh
68.8k8 gold badges110 silver badges191 bronze badges
3
Even if this post has its age: The error can generally occur when multiple redefinitions, even regardless of upper/lower case, coexist. This includes potential preprocessor definitions in the solution’s .vcprojx file!. Consider something like
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>$(Configuration);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
in the above mentioned file. Now, having «Debug» and «Release» configurations you will most probably run into some problems and a potential source for the C2059 error. I experienced exaclty this dilemma.
answered Apr 21, 2016 at 7:32
gilgamashgilgamash
86210 silver badges31 bronze badges
1
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Learn more about: Compiler Error C2059 |
Compiler Error C2059 |
03/26/2019 |
C2059 |
C2059 |
2be4eb39-3f37-4b32-8e8d-75835e07c78a |
Compiler Error C2059
syntax error : ‘token’
The token caused a syntax error.
The following example generates an error message for the line that declares j
.
// C2059e.cpp // compile with: /c // C2143 expected // Error caused by the incorrect use of '*'. int j*; // C2059
To determine the cause of the error, examine not only the line that’s listed in the error message, but also the lines above it. If examining the lines yields no clue about the problem, try commenting out the line that’s listed in the error message and perhaps several lines above it.
If the error message occurs on a symbol that immediately follows a typedef
variable, make sure that the variable is defined in the source code.
C2059 is raised when a preprocessor symbol name is re-used as an identifier. In the following example, the compiler sees DIGITS.ONE
as the number 1, which is not valid as an enum element name:
#define ONE 1 enum class DIGITS { ZERO, ONE // error C2059 };
You may get C2059 if a symbol evaluates to nothing, as can occur when /Dsymbol= is used to compile.
// C2059a.cpp // compile with: /DTEST= #include <stdio.h> int main() { #ifdef TEST printf_s("nTEST defined %d", TEST); // C2059 #else printf_s("nTEST not defined"); #endif }
Another case in which C2059 can occur is when you compile an application that specifies a structure in the default arguments for a function. The default value for an argument must be an expression. An initializer list—for example, one that used to initialize a structure—is not an expression. To resolve this problem, define a constructor to perform the required initialization.
The following example generates C2059:
// C2059b.cpp // compile with: /c struct ag_type { int a; float b; // Uncomment the following line to resolve. // ag_type(int aa, float bb) : a(aa), b(bb) {} }; void func(ag_type arg = {5, 7.0}); // C2059 void func(ag_type arg = ag_type(5, 7.0)); // OK
C2059 can occur for an ill-formed cast.
The following sample generates C2059:
// C2059c.cpp // compile with: /clr using namespace System; ref class From {}; ref class To : public From {}; int main() { From^ refbase = gcnew To(); To^ refTo = safe_cast<To^>(From^); // C2059 To^ refTo2 = safe_cast<To^>(refbase); // OK }
C2059 can also occur if you attempt to create a namespace name that contains a period.
The following sample generates C2059:
// C2059d.cpp // compile with: /c namespace A.B {} // C2059 // OK namespace A { namespace B {} }
C2059 can occur when an operator that can qualify a name (::
, ->
, and .
) must be followed by the keyword template
, as shown in this example:
template <typename T> struct Allocator { template <typename U> struct Rebind { typedef Allocator<U> Other; }; }; template <typename X, typename AY> struct Container { typedef typename AY::Rebind<X>::Other AX; // error C2059 };
By default, C++ assumes that AY::Rebind
isn’t a template; therefore, the following <
is interpreted as a less-than sign. You must tell the compiler explicitly that Rebind
is a template so that it can correctly parse the angle bracket. To correct this error, use the template
keyword on the dependent type’s name, as shown here:
template <typename T> struct Allocator { template <typename U> struct Rebind { typedef Allocator<U> Other; }; }; template <typename X, typename AY> struct Container { typedef typename AY::template Rebind<X>::Other AX; // correct };
Hi, i was trying to build some code using GAlib, the code is as follows:
// GATrainingDlg.cpp #include "GATrainingDlg.h" #include <stdio.h> #include <ga/ga.h> #include <ga/std_stream.h> #include <ga/GASimpleGA.h> #include <ga/GAGenome.h> #define INSTANTIATE_REAL_GENOME #include <ga/GARealGenome.h> void CGATrainingDlg::OnBnClickedGaTrainButton() { // TODO: Add your control notification handler code here GARealAlleleSetArray alleles2a; for(int i=0; i<m_nAlleleSetArrayLen; i++) alleles2a.add(0, 1, GAAllele::EXCLUSIVE, GAAllele::INCLUSIVE); GARealGenome genome2a(alleles2a, &CGATrainingDlg::Objective); GAParameterList params; GASimpleGA::registerDefaultParameters(params); params.set(gaNpCrossover, m_dPCross); params.set(gaNpMutation, m_dPMut); params.set(gaNnGenerations, m_nGAGen); params.set(gaNpopulationSize, m_nGAPopSize); params.set(gaNscoreFrequency, m_nScoreFreq); params.set(gaNflushFrequency, m_nFlushFreq); params.set(gaNselectScores, (int)GAStatistics::AllScores); // Now do a genetic algorithm for each one of the genomes that we created. GASimpleGA ga(genome2a); ga.parameters(params); ga.initialize(m_unSeed); CString cstrGAScoreFileName = m_cstrScoreFileSaveDest + m_cstrScoreFileName; ga.set(gaNscoreFilename, static_cast<LPCTSTR>(cstrGAScoreFileName)); cout << "nrunning ga number 2a (descending order, EXCLUSIVE)..." << endl; ga.evolve(); cout << "the ga generated:n" << ga.statistics().bestIndividual() << endl; } /*some other code*/
the compiler threw me 3 errors;
1>C:galib247ga/GAGenome.h(196): error C2059: syntax error : 'constant' 1>C:galib247ga/GAGenome.h(196): error C3805: 'constant': unexpected token, expected either '}' or a ',' 1>GATrainingDlg.cpp(135): error C2664: 'GA1DArrayAlleleGenome<T>::GA1DArrayAlleleGenome(unsigned int,const GAAlleleSet<T> &,GAGenome::Evaluator,void *)' : cannot convert parameter 1 from 'GARealAlleleSetArray' to 'unsigned int' 1> with 1> [ 1> T=float 1> ] 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>
for the first 2 errors, it points to GAGenome.h at this line:
enum {FIXED_SIZE = -1, ANY_SIZE = -10};
the whole GAGenome.h is like:
// $Header$ /* ---------------------------------------------------------------------------- genome.h mbwall 28jul94 Copyright (c) 1995 Massachusetts Institute of Technology DESCRIPTION: The base genome class just defines the genome interface - how to mutate, crossover, evaluate, etc. When you create your own genome, multiply inherit from the base genome class and the data type that you want to use. Use the data type to store the information and use the genome part to tell the GA how it should operate on the data. See comments below for further details. ---------------------------------------------------------------------------- */ #ifndef _ga_genome_h_ #define _ga_genome_h_ #include <ga/gaid.h> #include <ga/gaconfig.h> #include <ga/gaerror.h> #include <ga/GAEvalData.h> #include <ga/std_stream.h> class GAGeneticAlgorithm; class GAGenome; /* ---------------------------------------------------------------------------- Genome ------------------------------------------------------------------------------- Deriving your own genomes: For any derived class be sure to define the canonical methods: constructor, copy constructor, operator=, and destructor. Make sure that you check for a self-copy in your copy method (it is possible that a genome will be selected to cross with itself, and self-copying is not out of the question) To work properly with the GAlib, you MUST define the following: YourGenome( -default-args-for-your-genome ) YourGenome(const YourGenome&) virtual ~YourGenome() virtual GAGenome* clone(GAGenome::CloneMethod) virtual copy(const GAGenome&) If your genome class defines any new properties you should to define: virtual int read(istream&) virtual int write(ostream&) const virtual int equal(const GAGenome&) const When you derive a genome, don't forget to use the _evaluated flag to indicate when the state of the genome has changed and an evaluation is needed. Assign a default crossover method so that users don't have to assign one unless they want to. Do this in the constructor. It is a good idea to define an identity for your genome (especially if you will be using it in an environment with multiple genome types running around). Use the DefineIdentity/DeclareIdentity macros (defined in id.h) to do this in your class definition. Brief overview of the member functions: initialize Use this method to set the initial state of your genomes once they have been created. This initialization is for setting up the genome's state, not for doing the basic mechanics of genome class management. The default behaviour of this method is to change randomly the contents of the genome. If you want to bias your initial population, this is where to make that happen. The initializer is used to initialize the genome (duh). Notice that the state of the genome is unknown - memory may or may not have been allocated, and the genome may or may not have been used before. So your initializer should first clean up as needed, then do its thing. The initializer may be called any number of times (unlike a class constructor which is called only once for a given instance). mutate Mutate the genome with probability as specified. What mutation means depends upon the data type of the genome. For example, you could have a bit string in which 50% mutation means each bit has a 50% chance of getting flipped, or you could have a tree in which 50% mutation means each node has a 50% chance of getting deleted, or you could have a bit string in which 50% mutation means 50% of the bits ACTUALLY get flipped. The mutations member returns the number of mutations since the genome was initialized. The mutator makes a change to the genome with likeliehood determined by the mutation rate parameter. The exact meaning of mutation is up to you, as is the specific meaning of the mutation rate. The function returns the number of mutations that actually occurred. crossover Genomes don't really have any clue about other genomes, so we don't make the crossover a member function. Instead, each genome kind of knows how to mate with other genomes to generate offspring, but they are not capable of doing it themselves. The crossover member function is used to set the default mating mode for the genomes - it does not actually perform the crossover. This way the GA can use asexual crossover if it wants to (but genomes only know how to do the default sexual crossover). This also lets you do funky stuff like crossover between different data types and group sex to generate new offspring. We define two types of crossover: sexual and asexual. Most GAlib algorithms use the sexual crossover, but both are available. Each genome knows the preferred crossover method, but none is capable of reproducing. The genetic algorithm must actually perform the mating because it involves another genome (as parent and/or child). evaluator Set the genome's objective function. This also sets marks the evaluated flag to indicate that the genome must be re-evaluated. Evaluation happens on-demand - the objective score is not calculated until it is requested. Then it is cached so that it does not need to be re- calculated each time it is requested. This means that any member function that modifies the state of the genome must also set the evaluated flag to indicate that the score must be recalculated. The genome objective function is used by the GA to evaluate each member of the population. comparator This method is used to determine how similar two genomes are. If you want to use a different comparison method without deriving a new class, then use the comparator function to do so. For example, you may want to do phenotype- based comparisons rather than genotype-based comparisons. In many cases we have to compare two genomes to determine how similar or different they are. In traditional GA literature this type of function is referred to as a 'distance' function, probably because bit strings can be compared using the Hamming distance as a measure of similarity. In GAlib, we define a genome comparator function that does exactly this kind of comparison. If the genomes are identical, the similarity function should return a value of 0.0, if completely different then return a value greater than 0. The specific definition of what "the same" and what "different" mean is up to you. Most of the default comparators use the genotype for the comparison, but you can use the phenotype if you prefer. There is no upper limit to the distance score as far as GAlib is concerned. The no-op function returns a -1 to signify that the comparison failed. evalData The evalData member is useful if you do not want to derive a new genome class but want to store data with each genome. When you clone a genome, the eval data also gets cloned so that each genome has its own eval data (unlike the user data pointer described next which is shared by all genomes). userData The userData member is used to provide all genomes access to the same user data. This can be a pointer to anything you want. Any genome cloned from another will share the same userData as the original. This means that all of the genomes in a population, for example, share the same userData. score Evaluate the 'performance' of the genome using the objective function. The score is kept in the 'score' member. The 'evaluated' member tells us whether or not we can trust the score. Be sure to set/unset the 'evaluated' member as appropriate (eg cross and mutate change the contents of the genome so they unset the 'evaluated' flag). If there is no objective function, then simply return the score. This allows us to use population-based evaluation methods (where the population method sets the score of each genome). clone This method allocates space for a new genome and copies the original into the new space. Depending on the argument, it either copies the entire original or just parts of the original. For some data types, clone contents and clone attributes will do the same thing. If your data type requires significant overhead for initialization, then you'll probably want to distinguish between cloning contents and cloning attributes. clone(cont) Clone the contents of the genome. Returns a pointer to a GAGenome (which actually points to a genome of the type that was cloned). This is a 'deep copy' in which every part of the genome is duplicated. clone(attr) Clone the attributes of the genome. This method does nothing to the contents of the genome. It does NOT call the initialization method. For some data types this is the same thing as cloning the contents. ---------------------------------------------------------------------------- */ class GAGenome : public GAID { public: GADefineIdentity("GAGenome", GAID::Genome); public: typedef float (*Evaluator)(GAGenome &); typedef void (*Initializer)(GAGenome &); typedef int (*Mutator)(GAGenome &, float); typedef float (*Comparator)(const GAGenome&, const GAGenome&); typedef int (*SexualCrossover)(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*); typedef int (*AsexualCrossover)(const GAGenome&, GAGenome*); public: static void NoInitializer(GAGenome &); static int NoMutator(GAGenome &, float); static float NoComparator(const GAGenome&, const GAGenome&); public: enum Dimension {LENGTH = 0, WIDTH = 0, HEIGHT = 1, DEPTH = 2}; enum CloneMethod {CONTENTS = 0, ATTRIBUTES = 1}; enum {FIXED_SIZE = -1, ANY_SIZE = -10}; public: // The GNU compiler sucks. It won't recognize No*** as a member of the genome // class. So we have to use 0 as the defaults then check in the constructor. GAGenome(Initializer i=0, Mutator m=0, Comparator c=0); GAGenome(const GAGenome&); GAGenome & operator=(const GAGenome & arg){copy(arg); return *this;} virtual ~GAGenome(); virtual GAGenome* clone(CloneMethod flag=CONTENTS) const; virtual void copy(const GAGenome &); #ifdef GALIB_USE_STREAMS virtual int read(STD_ISTREAM &) { GAErr(GA_LOC, className(), "read", gaErrOpUndef); return 0; } virtual int write(STD_OSTREAM &) const { GAErr(GA_LOC, className(), "write", gaErrOpUndef); return 0; } #endif virtual int equal(const GAGenome &) const { GAErr(GA_LOC, className(), "equal", gaErrOpUndef); return 1; } virtual int notequal(const GAGenome & g) const { return (equal(g) ? 0 : 1); } public: int nevals() const {return _neval;} float score() const { evaluate(); return _score; } float score(float s){ _evaluated=gaTrue; return _score=s; } float fitness(){return _fitness;} float fitness(float f){return _fitness = f;} GAGeneticAlgorithm* geneticAlgorithm() const {return ga;} GAGeneticAlgorithm* geneticAlgorithm(GAGeneticAlgorithm& g){return(ga=&g);} void * userData() const {return ud;} void * userData(void * u){return(ud=u);} GAEvalData * evalData() const {return evd;} GAEvalData * evalData(const GAEvalData& o) {delete evd; evd = o.clone(); return evd;} float evaluate(GABoolean flag = gaFalse) const; Evaluator evaluator() const {return eval;} Evaluator evaluator(Evaluator f) { _evaluated=gaFalse; return(eval=f); } void initialize(){_evaluated=gaFalse; _neval=0; (*init)(*this);} Initializer initializer() const {return init;} Initializer initializer(Initializer op){return (init=op);} int mutate(float p){ return((*mutr)(*this,p)); } Mutator mutator() const {return mutr;} Mutator mutator(Mutator op){return (mutr=op);} float compare(const GAGenome& g) const {return (*cmp)(*this,g);} Comparator comparator() const {return cmp;} Comparator comparator(Comparator c){return (cmp=c);} SexualCrossover crossover(SexualCrossover f) { return sexcross = f; } SexualCrossover sexual() const { return sexcross; } AsexualCrossover crossover(AsexualCrossover f) { return asexcross = f; } AsexualCrossover asexual() const { return asexcross; } protected: float _score; // value returned by the objective function float _fitness; // (possibly scaled) fitness score GABoolean _evaluated; // has this genome been evaluated? unsigned int _neval; // how many evaluations since initialization? GAGeneticAlgorithm* ga; // the ga that is using this genome void* ud; // pointer to user data Evaluator eval; // objective function GAEvalData* evd; // evaluation data (specific to each genome) Mutator mutr; // the mutation operator to use for mutations Initializer init; // how to initialize this genome Comparator cmp; // how to compare two genomes of this type SexualCrossover sexcross; // preferred sexual mating method AsexualCrossover asexcross; // preferred asexual mating method }; #ifdef GALIB_USE_STREAMS inline STD_OSTREAM & operator<< (STD_OSTREAM& os, const GAGenome& genome) { genome.write(os); return(os); } inline STD_ISTREAM & operator>> (STD_ISTREAM & is, GAGenome& genome) { genome.read(is); return(is); } #endif inline int operator== (const GAGenome& a, const GAGenome& b) { return a.equal(b); } inline int operator!= (const GAGenome& a, const GAGenome& b) { return a.notequal(b); } #endif
I have built and ran every example in the GAlib package without any problem. I just come across these issues when I tried to use it in MFC. The code is based on an example in GAlib:
/* ---------------------------------------------------------------------------- ex21.C mbwall 1jan96 Copyright (c) 1995-1996 Massachusetts Institute of Technology DESCRIPTION: This example illustrates various uses of the AlleleSet in concert with the ArrayAlleleGenome. In particular, we use the RealGenome to show how you can use the enumerated and bounded types of allele sets. You can define one allele set for an entire array, or you can define one allele set for each element in the array. The constructor that you use to create the array determines which behaviour you'll get. ---------------------------------------------------------------------------- */ #include <stdio.h> #include <ga/ga.h> #include <ga/std_stream.h> #define cout STD_COUT #define endl STD_ENDL #define INSTANTIATE_REAL_GENOME #include <ga/GARealGenome.h> float Objective1(GAGenome &); float Objective2(GAGenome &); float Objective3(GAGenome &); float Objective4(GAGenome &); int main(int argc, char** argv) { cout << "Example 21nn"; cout << "This example shows various uses of the allele set objectn"; cout << "in combination with the real number genome.nn"; cout.flush(); // See if we've been given a seed to use (for testing purposes). When you // specify a random seed, the evolution will be exactly the same each time // you use that seed number. unsigned int seed = 0; for(int ii=1; ii<argc; ii++) { if(strcmp(argv[ii++],"seed") == 0) { seed = atoi(argv[ii]); } } // First make a bunch of genomes. We'll use each one in turn for a genetic // algorithm later on. Each one illustrates a different method of using the // allele set object. Each has its own objective function. int length = 8; // This genome uses an enumerated list of alleles. We explictly add each // allele to the allele set. Any element of the genome may assume the value // of any member of the allele set. GARealAlleleSet alleles1; alleles1.add(-10); alleles1.add(0.1); alleles1.add(1.0); alleles1.add(10); alleles1.add(100); GARealGenome genome1(length, alleles1, Objective1); // This genome uses a bounded set of continous numbers. The default arguments // are INCLUSIVE for both the lower and upper bounds, so in this case the // allele set is [0,1] and any element of the genome may assume a value [0,1]. GARealAlleleSet alleles2(0, 1); GARealGenome genome2(length, alleles2, Objective2); // Similar to the previous set, but this one has EXCLUSIVE bounds and we create // the allele set explicitly (even though in this case GARealAlleleSetArray alleles2a; for(int i=0; i<length; i++) alleles2a.add(0, 1, GAAllele::EXCLUSIVE, GAAllele::EXCLUSIVE); GARealGenome genome2a(alleles2a, Objective2); // Here we create a genome whose elements may assume any value in the interval // [0.0, 10.0) discretized on the interval 0.5, i.e. the values 0.0, 0.5, 1.0, // and so on up to but not including 10.0. // Note that the default operators for the real genome are uniform initializer, // gaussian mutator, and uniform crossover. Since gaussian is not the behavior // we want for mutation, we assign the flip mutator instead. GARealAlleleSet alleles3(0,10,0.5,GAAllele::INCLUSIVE,GAAllele::EXCLUSIVE); GARealGenome genome3(length, alleles3, Objective3); genome3.crossover(GARealUniformCrossover); genome3.mutator(GARealSwapMutator); // This genome is created using an array of allele sets. This means that each // element of the genome will assume a value in its corresponding allele set. // For example, since the first allele set is [0,10], the first element of the // genome will be in [0,10]. Notice that you can add allele sets in many other // ways than those shown. GARealAlleleSetArray alleles4; alleles4.add(0,10); alleles4.add(50,100); alleles4.add(-10,-5); alleles4.add(-0.01,-0.0001); alleles4.add(10000,11000); GARealGenome genome4(alleles4, Objective4); // Now that we have the genomes, create a parameter list that will be used for // all of the genetic algorithms and all of the genomes. GAParameterList params; GASteadyStateGA::registerDefaultParameters(params); params.set(gaNnGenerations, 500); params.set(gaNpopulationSize, 110); params.set(gaNscoreFrequency, 10); params.set(gaNflushFrequency, 50); params.set(gaNselectScores, (int)GAStatistics::AllScores); params.parse(argc, argv, gaFalse); // Now do a genetic algorithm for each one of the genomes that we created. GASteadyStateGA ga1(genome1); ga1.parameters(params); ga1.set(gaNscoreFilename, "bog1.dat"); cout << "nrunning ga number 1 (alternate allele(0) and allele(3))..."<<endl; ga1.evolve(seed); cout << "the ga generated:n" << ga1.statistics().bestIndividual() << endl; GASteadyStateGA ga2(genome2); ga2.parameters(params); ga2.set(gaNscoreFilename, "bog2.dat"); cout << "nrunning ga number 2 (continuous descending order)..." << endl; ga2.evolve(); cout << "the ga generated:n" << ga2.statistics().bestIndividual() << endl; GASteadyStateGA ga2a(genome2a); ga2a.parameters(params); ga2a.set(gaNscoreFilename, "bog2a.dat"); cout << "nrunning ga number 2a (descending order, EXCLUSIVE)..." << endl; ga2a.evolve(); cout << "the ga generated:n" << ga2a.statistics().bestIndividual() << endl; GASteadyStateGA ga3(genome3); ga3.parameters(params); ga3.set(gaNscoreFilename, "bog3.dat"); cout << "nrunning ga number 3 (discretized ascending order)..." << endl; ga3.evolve(); cout << "the ga generated:n" << ga3.statistics().bestIndividual() << endl; GASteadyStateGA ga4(genome4); ga4.parameters(params); ga4.set(gaNscoreFilename, "bog4.dat"); cout << "nrunning ga number 4 (maximize each gene)..." << endl; ga4.evolve(); cout << "the ga generated:n" << ga4.statistics().bestIndividual() << endl; return 0; } // This objective function tries to maximize the occurance of the first and // fourth alleles. It tries to put the first allele in the even elements and // the fourth allele in the odd elements. float Objective1(GAGenome& g) { GARealGenome& genome = (GARealGenome&)g; float value=0.0; for(int i=0; i<genome.length(); i++){ if(i%2 == 0 && genome.gene(i) == genome.alleleset().allele(0)) value += 1.0; if(i%2 != 0 && genome.gene(i) == genome.alleleset().allele(3)) value += 1.0; } return value; } // This objective function tries to generate a straight - it gives higher score // to a genome whose elements descend in value. If two genomes both have // elements in strictly descending order, they get the same score regardless // of their values. float Objective2(GAGenome& g) { GARealGenome& genome = (GARealGenome&)g; float value=0.0; for(int i=1; i<genome.length(); i++) if(genome.gene(i) < genome.gene(i-1)) value += 1.0; return value; } // This objective function generates a straight by giving higher score to a // genome whose elements ascend in value. float Objective3(GAGenome& g) { GARealGenome& genome = (GARealGenome&)g; float value=0.0; for(int i=1; i<genome.length(); i++) if(genome.gene(i) > genome.gene(i-1)) value += 1.0; return value; } // This objective tries to maximize each element in the genome. float Objective4(GAGenome& g) { GARealGenome& genome = (GARealGenome&)g; float value=0.0; for(int i=0; i<genome.length(); i++) value += genome.gene(i); return value; }
so how to fix these problems?
cheers
I want to read and print the first two lines from a text file.
Problem is, I get the error: error c2059: syntax error: constant and it points to the first line in my text file.
Any ideas?
The file.txt:
5
5
3
1 1 1 0 0
0 1 0 0 1
0 1 0 1 0
1 0 1 0 1
1 1 0 1 1
The code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
int line, col, gen;
fp = fopen("file.txt", "rt");
fscanf(fp, "%dn,%dn", &line, &col);
printf("line: %d, col: %dn", line, col);
fclose(fp);
return 0;
}
asked Dec 11, 2014 at 10:42
8
Visual Studio will compile every file in your project. This includes file.txt
, if you have added it as a file to your project.
To prevent Visual Studio from compiling this, you need to tell Visual Studio it’s a ‘Content’ file. Take a look at File Properties at Build Action Property.
Content — The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.
answered Dec 11, 2014 at 11:02
bzeamanbzeaman
1,12811 silver badges28 bronze badges
1
takeiteasy 0 / 0 / 0 Регистрация: 15.10.2011 Сообщений: 10 |
||||||||
1 |
||||||||
14.12.2011, 20:47. Показов 5113. Ответов 1 Метки нет (Все метки)
Подскажите пожалуйста почему выдает ошибку error C2059: syntax error : ‘constant’
пробовала через enum — тоже ошибки выдает.
0 |
dino-4udo -5 / 6 / 4 Регистрация: 16.12.2010 Сообщений: 68 |
||||
14.12.2011, 20:57 |
2 |
|||
Попробуй так
0 |