#Help for function

16 messages · Page 1 of 1 (latest)

soft sequoia
#

main.cpp :

#include <iostream>
#include "bitentete.h"
using namespace std;

int main() {
int age;
cin >> age;
/* cout<<"Testou";
if (peutPasserIf(age) == true) {
cout << "Entre mon gars, amuse toi bien.";
}
else {
cout << "Degage mon gate";
}*/

baSwitch(age);
return 0;

}

bit.cpp :

#include <string>
#include <iostream>
#include "bitentete.h"
using namespace std;

int agePlusOneYear(int age){
return age+1;
}

int ageMinusOneYear(int age) {
return age - 1;
}

bool peutPasserIf(int age) {
return (age >= 18);
}

string baSwitch(int age) {
switch (age) {
case 18:
cout << "Tu rentres piles poil mon ane !";
case 666:
cout << "Entre mon cretin.";
case 20:
cout << "Alors la vingtaine mon gars ca va ?";
case 16:
cout << "Désolé, ouvert qu'au papy.";
}
return "Tiens une bouteille de vingt";
}

bitentete.h :

#ifndef BIT_H_INCLUDED

#define BIT_H_INCLUDED

int agePlusOneYear(int age);
int ageMinusOneYear(int age);
//bool peutPasserIf(int age);
string baSwitch(int age);

#endif // BIT_H_INCLUDED


Issue: E0311
cannot override functions distinguished by return type only (with google translate because i'm french and the error was in my language)

The name of baSwitch is underlined in red in bit.cpp and .h

verbal flickerBOT
#

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.

#
How to Format Code on Discord
Markup

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

Result
int main() {}
verbal flickerBOT
#

main.cpp :

#include <iostream>
#include "bitentete.h"
using namespace std;

int main() {
  int age;
  cin >> age;
  /*    cout<<"Testou";
      if (peutPasserIf(age) == true) {
          cout << "Entre mon gars, amuse toi bien.";
      }
      else {
          cout << "Degage mon gate";
      }*/

  baSwitch(age);
  return 0;
}

bit.cpp :

#include <iostream>
#include <string>
#include "bitentete.h"
    using namespace std;

int agePlusOneYear(int age) {
  return age + 1;
}

int ageMinusOneYear(int age) {
  return age - 1;
}

bool peutPasserIf(int age) {
  return (age >= 18);
}

string baSwitch(int age) {
  switch (age) {
    case 18:
      cout << "Tu rentres piles poil mon ane !";
    case 666:
      cout << "Entre mon cretin.";
    case 20:
      cout << "Alors la vingtaine mon gars ca va ?";
    case 16:
      cout << "Désolé, ouvert qu'au papy.";
  }
  return "Tiens une bouteille de vingt";
}

bitentete.h :

#ifndef BIT_H_INCLUDED

#define BIT_H_INCLUDED

    int
    agePlusOneYear(int age);
int ageMinusOneYear(int age);
// bool peutPasserIf(int age);
string baSwitch(int age);

#endif // BIT_H_INCLUDED


Issue: E0311
cannot override functions distinguished by return type only (with google translate because i'm french and the error was in my language)

The name of baSwitch is underlined in red in bit.cpp and .h

FEATOO
quartz eagle
#

not in class , need use extern in header

soft sequoia
#

i'm a beginner, i don't understand what are you saying and i'm not sure i used a "class", it's not orientoed objet

quartz eagle
#

understand now ?

#

example:

extern int agePlusOneYear(int age);
soft sequoia
#

i don't think it's the problem, agePlusOneYear works very well

#

and minus to

#

o

shut totem
#

string isn't known in the header bitentete.h.
You need to #include <string>
Also:

verbal flickerBOT
#
Why Is `using namespace std` Considered Bad Practice?

using namespace std will import all the symbols from std into the enclosing namespace. This can easily lead to name collisions, as the standard library is filled with common names: get, count, map, array, etc.

A key concern with using namespace std; is not what is imported now but rather what may suddenly be imported in the future.

While using namespace std; is alright for tiny projects, it is important to move away from it as soon as possible. Consider less intrusive alternatives:

// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x;
soft sequoia
#

okay

#

it works but the error is really weird xDD