Desctructor declaration problem

Sorry for bothering, but I have a problem which I do not get.
I compiled a header file for a class and declared for Account() and getName() a constructor and a destructor in public. Background is that I want to close a external file with the desctructor.
The problem is now that the desctructor ~Account() does not provide any error; but the ~getName() provides "error: expected class-name before '(' token".
For me, it is just the same and it is only a declaration. I tried several things, but it does not change anything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>

using std::string;

class Account
{     
        std::ofstream Acc_file_;
        string name_;
        bool b_name_;
        int l_name_;

        string New_PW_;
        int l_PW_;

    public:
        Account();
        ~Account();

        getName_();
        ~getName_();
        string n_;

        void PW_();
        string P_;

        void Login_();


    protected:


};

#endif // ACCOUNT_H 
Having a ~ in a function name is only valid for destructors. You can't do it for other functions.

~getName_() can't possibly be a destructor.

but the ~getName() provides "error: expected class-name before '(' token".
What are your trying to achieve?
dtor is for the class at hand, in this case, account.
you rarely need explicit dtor: the compiler handles most object destruction for you cleanly. So the first question whether you need one or not should be examined, look up the rule of 3, rule of 5, and rule of zero. rule of 5 is a growth of the rule of 3 so those 2 are very similar.

so, not sure what your confusion is, but the string object in c++ already does its own destruction and you don't need any kind of destructor in your class to destroy this member; and in fact, you can't do that (but your class' destructor can call something itself if needed, so pretend you did need to destroy name string yourself: you could do it in your ~account() dtor. You don't need them for functions, that is something that has confused you).

~Account(); //this is correct, IF YOU NEED IT based off the rules I said.
the other stuff with a ~ in front of it is simply wrong: you have misunderstood the concept.
Topic archived. No new replies allowed.