Member function not declared

Hey so im working on this problem I dont understand how im getting it wrong Im following the syntax just like how they have it explained. Can I get some pointers on what I am not getting.

link to problem: https://www.codecademy.com/courses/learn-c-plus-plus/lessons/cpp-classes-and-objects/exercises/cpp-class-members

Could it be as simple as a missing keyword, ‘function’?

no I dont think there is a function keyword for c++ look at how they wrote their method example.

1 Like

Be careful with std::string vs. string here, that could cause you trouble. I’m not sure the provided error is all that helpful but all you want here is the declaration, not a definition, of your method.

Both your method declarations should look more like the following short example (under public)-

int member_func(pars);

They want you to write the definitions in a separate file.

3 Likes

is that because using namespace std; is not written? because I added it and still gave me the same error. what is the difference on it?

In terms of namespaces, yes, string would not be directly available in this scope unless you added that namespace with using namespace.

As for an error I’m not sure what code you’re now using and what error you received. Have you changed your methods to just be declarations as per the second part of the previous post?

See How do I format code in my posts? so we’re not left guessing.

1 Like

thanks I got I got the answer correct now but it doesn’t make sense though because when you learn variables earlier they dont even require that you write that and it still works fine if I were to write string name;

1 Like

Unfortunately you can’t be sure what tests are going on in CC environment, there’s no guarantee the code is compiled or tested as there’s simpler routes to check just the contents of a file or similar. I’d advise trying to compile this on your own device and viewing the result for yourself if you want to be sure.

As a quick test-

# include <string> int main() { std::string test1; // see where the error crops up string test2; return 0; }
1 Like

ah wow ok I see thank you!

1 Like

I never seen variables with std:: I thought that was only a cout thing.

It’s the namespace for the standard libraries and there are quite a lot of possibilities…
https://en.cppreference.com/w/cpp/header

Long strong short you’ll probably be seeing a lot of it :slightly_smiling_face: