Reappearing error in C++ track, raindrops

I am facing a problem with the Raindrops problem under C++ track. I keep getting an error saying ‘convert’ is not a member of ‘raindrops’ and I don’t understand. I have named my function ‘convert’ as stated but the error keeps on appearing. I’d appreciate any help given


Picture for clarity

  1. Please do share code and errors – as text in a codeblock. It’s really hard to reproduce issues using code from images. More so for the visually impaired.
  2. While posting your code and errors, could you include the header file? Is the function defined in there?

That is true and I will use this knowledge next time when posting thank you.

----Contents of raindrop.cpp--------
#include “raindrops.h”

namespace raindrops {
string convert(int n){
string finalStr;
if(a== 0){
cout << “test passed for 3\n”;
finalStr += “Pling”;
}
if(b == 0){
cout << “test passed for 5\n”;
finalStr += “Plang”;
}
if(c == 0){
cout << “test passed for 7\n”;
finalStr += “Plong”;
}
if(a != b && b != c){
finalStr = to_string(n);
}
cout << finalStr << endl;
return finalStr;
}
} // namespace raindrops

contents of raindrops.h-
#if !defined(RAINDROPS_H)
#define RAINDROPS_H

namespace raindrops {

} // namespace raindrops

#endif // RAINDROPS_H

These are the contents of both files.

The Hello World example exercise has function definition ... hello() { ... } in the .cpp file, and it has function declaration ... hello(); in the .h file.

We need something comparable here: you will need to add a function declaration to raindrops.h

The test file has

#include "raindrops.h"

When the test file is being compiled, the compiler does not see the function definition string convert(int n){ ... } in raindrop.cpp

Oh okay. I am new to using header files so I thought the system would handle that. Thank you very much. I will do some research on this later to better understand

As a code block:

----Contents of raindrop.cpp--------
#include “raindrops.h”

namespace raindrops {
string convert(int n){
string finalStr;
if(a== 0){
cout << “test passed for 3\n”;
finalStr += “Pling”;
}
if(b == 0){
cout << “test passed for 5\n”;
finalStr += “Plang”;
}
if(c == 0){
cout << “test passed for 7\n”;
finalStr += “Plong”;
}
if(a != b && b != c){
finalStr = to_string(n);
}
cout << finalStr << endl;
return finalStr;
}
} // namespace raindrops
—contents of raindrops.h-—
#if !defined(RAINDROPS_H)
#define RAINDROPS_H

namespace raindrops {

} // namespace raindrops

#endif // RAINDROPS_H

There is a new concept with an exercise about headers. Maybe that can help you?

2 Likes