Please, How to write well the cpp for my h file ?

I have many compiler problems with this file :
Note I have a Wwin namespace.

I have tried to write the h file by combining namespace, ::Myswin (the name of my class) and all I get are errors. Please Help

The .h file :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef WWIN_H
#define WWIN_H

#include <string>
#include <QMessageBox>

namespace Wwin {

class Myswin
{
public:
    Myswin(){}
    ~Myswin(){}

    enum   Msg_resp {Msg_yes, Msg_no, Msg_cancel};
    static Msg_resp Msg_YesNo(std::string,std::string);
    static Msg_resp Msg_YesNoCancel(std::string,std::string);

};

}
#endif // WWINU_H 


and this is the Icomplete cpp file

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
#include "wwin.h"
#include <QMessageBox>
#include <string>






Myswin::Msg_resp Myswin::MsgGenericYesNoCancel(string title,string msg,QMessageBox::StandardButton tipo_yesnocancel)
{
   Msg_resp resp;
   QMessageBox::StandardButton reply;
  //QApplication::focusWidget ()

reply = QMessageBox::question(this, tr(title), tr(msg),tipo_yesnocancel);
if (reply == QMessageBox::Yes)
    resp=yes;
else if (reply == QMessageBox::No)
        resp=no;
else
   questionLabel->setText(tr("Cancel"));  resp=cancel;

return resp;
}




Myswin::Msg_resp Wwin::Myswin::Msg_YesNo(string title,string msg)
{
    return Wwin::Myswin::wwMsgGenericYesnoCancel(title,msg,QMessageBox::Yes | QMessageBox::No);
}

Myswin::Msg_resp Wwin::Myswin::Message_YesNoCancel(string title,string msg)
{
return  Wwin::Myswin::MsgGenericYesnoCancel(title,msg,QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
}

Last edited on
Ok, firstly your class has no method named "MsgGenericYesNoCancel". You can't assign new elements to the class if you've already got the header file done. The class is defined at this point. If you want to add a new function, you need to declare it in the header first.

Secondly, you need to define the string parameters of the functions as std::string - at the moment I expect you're getting errors telling you that it doesn't know what string is?

You also need to put WWin:: infront of the type specifiers for your enum.
Last edited on
Also, on line 22, you will always be setting the response to cancel. If you don't enclose the statements after if/else if/else in brackets {}, then it will only consider the first statement as part of that block. The resp=cancel; line might as well be on the line above return resp
I'm working on it.
Maybe that some compìle errors can be hide - show another errors?
Sorry, I have no idea what you're asking.
I refer to the posibility of some errors can hide others
I've rewrited the code and now I get other kind of errors.
The same situation happens in other files, can be the compiler are becoming mad because of my bad code ?
Thanks
If you don't tell us what the errors are, then it's unlikely we'll be able to help you. I can't compile the program in my head to see what's wrong with it.

Read the errors, they're usually quite clear. Post any you don't understand, and perhaps and update of your code files.
Topic archived. No new replies allowed.