#new to c++ & not sure how to solve this error?

1 messages · Page 1 of 1 (latest)

candid mothBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

native kestrel
#
#define MATCHINGPROBLEM_H_INCLUDED

#pragma once

#include <vector>
#include <random>
#include <algorithm>
#include <iostream>
#include "GeneticAlgorithmSolver.h"

class GeneticAlgorithmSolver {
public:
    GeneticAlgorithmSolver(const MatchingProblem& problem, int populationSize, int selectionSize);

    void initialize(const std::vector<double>& lowerBounds, const std::vector<double>& upperBounds);

    void iterate();

    double getMaxParameterRange() const;

    std::vector<double> getCurrentBest() const;

private:
    const MatchingProblem& problem;
    int populationSize;
    int selectionSize;
    std::vector<std::vector<double>> population;
    std::vector<double> costs;
    std::vector<double> lowerBounds;
    std::vector<double> upperBounds;
    std::default_random_engine rng;

    void generateRandomParameters(std::vector<double>& parameters);

    void evaluatePopulation();

    void selectParents(std::vector<std::vector<double>>& parents);

    void crossover(const std::vector<std::vector<double>>& parents, std::vector<std::vector<double>>& offspring);

    void mutate(std::vector<std::vector<double>>& population);
};

#endif // MATCHINGPROBLEM_H_INCLUDED
dusky coral
#

!code

candid mothBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
dusky coral
#

How are you compiling your code?

native kestrel
dusky coral
#

And how are you compiling, i.e. with what command?

latent grail
native kestrel
latent grail
#

normally you'd expect it to define matching problem

latent grail
#

so that'd be my bet

native kestrel
#

codeblock

#

sorry

latent grail
#

mandatory mention that beginner introductory videos don't have a good average quality

#

especially if it's only 1 hour

dusky coral
#

Also why are you declaring 2 functions inside your main?

native kestrel
native kestrel
dusky coral
#

No, not necessarily, but you just can't declare functions inside other functions

native kestrel
#

oh? is that why it might be an error

dusky coral
#

There seem to be multiple errors like e.g. you not defining the class MatchingProblem anywhere but presumably defining GeneticAlgorithmSolver in 2 different header files (we only see the MatchingProblem.h file, but in there you defined GeneticAlgorithmSolver but never MatchingProblem.

Also in your header why are you using 2 include guards?
Either use the ifndef, define, endif chain or just use the pragma once, but there's no need for both in the same file

native kestrel
candid mothBOT
#

@native kestrel Has your question been resolved? If so, type !solved :)

native kestrel
#

ERROR MSG:

latent grail
#

what do you expect this to do/achieve GeneticAlgorithmSolver solver(problem, numParameters, 5000, 100);
and how did you ensure it would work/succeed to do what you wanted

native kestrel
latent grail
#

you didn't answer the second part

#

got to leave but GeneticAlgorithmSolver is a type

#

you want to create an instance of it

#

to do that you need a constructor that matches the argument you're passing in

#

you're passing in 4 arguments

#

there are no constructor that take 4 arguments

native kestrel
latent grail
#

might I suggest you take up a tutorial on how to write classes in c++

native kestrel
#

or something with the void parts of my code

latent grail
#

where did you define those member functions

#

most likely you've put them in their own .cpp files, so the question is how you've told codeblocks that those files were part of your project, and should be compiled and linked together with whatever .cpp file contains your main function

#

I think it also has to be said by this point that I really don't recommend using codeblock as your c++ ide, but I also was too lazy to argue the point or try to figure out if you had any constraints that forced you to use it

native kestrel
latent grail
#

haven't looked in details but you have multiple .cpp files, so the pending issue is how yo'uve told codeblocks about all of them

latent grail
#

so I'd assume that in some way shape or form codeblocks is only trying to compile one cpp file

#

and I don't use codeblock so I can't help you with setting that up

native kestrel
#

but they are all on the same folder?

#

oh

latent grail
#

cause you seem to be using codeblocks builtin build system

#

ok but being in the same folder means little to codeblock

#

like codeblock almost certainly shouldn't try to compile CW3.layout

native kestrel
#

oh

latent grail
#

so that's generally just not how it works

#

the build system has to be told in some way about what files are part of the project and what files it has to deal with

#

google "codeblock multiple files compilation" or "codeblock setting up project" or whatever

native kestrel
#

okay thanks

#

do u also suggest i just redo the project again?

candid mothBOT
#

@native kestrel Has your question been resolved? If so, type !solved :)

latent grail
#

I don't follow why you would/should

#

about any project setup allows you to add existing files

#

and if codeblock doesn't with its projects then it's really something that politically correct speech cannot name

candid mothBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.

native kestrel
#

!howto ask

candid mothBOT
# native kestrel !howto ask
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C/C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
native kestrel
#

!solved

candid mothBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity