Getting this error for the first time(don't kno what to do)

Hey guys,so I'm working on a small project of mine and got some errors while compiling the source.

The program has a Config class to store the configuration of an IRC server.This class has two member variables of the Settings class and the Metadata class.The Metadata class stores the number of settings currently stored in the configuration file.
The Settings class stores the actual settings of the server and the Config class uses tht settings object to parse through the values.I have also made a very noobish Settings_Exception class which gives exceptions for the following wrong inputs:-
i)Wrong input of port number
ii)Wrong input of server

This Settings_Exception class is the one tht is giving me an headache.I'm getting this weird errors tht I've never seen before and am having a hard time solving.Here are the required parts of the source:-

This is the Settings_Exception class:-
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "./Exceptions.hpp"
#include <utility>
#include <iostream>
#include <cstdlib>

/* Error types:-
 * i)No errors(error type 0)
 * ii)Wrong assignement of port(error type 1) 
 * iii)Wrong assignment of server domain(error type 2)
 * This errors are stored in msg_error variable.
*/

class Settings_Exception : public Exception
{
private:
    unsigned short Port;
    std::string Serv;
    std::string Chan;
    int msg_error;//Stores the error type

    friend class Settings;
  
    void gPort(unsigned short &port) //To be used in a try-catch block 
    { 
        Port = port; 
        CheckPort();
        Catch(); 
    }
    void gServ(std::string &serv) //To be used in a try-catch block
    {   
        Serv = serv; 
        CheckServ();
        Catch(); 
    }
    void gChan(std::string &chan) //To be used in a try-catch block
    { Chan = chan; }
    
    //Helper functions....to be not used by the
    //programmer...just inside this header.
    void CheckServ()   
    {
        std::string a,b,c;
        a = Serv.substr(Serv.size()-3,50);
        //b = Serv.substr(Serv.size()-2,50);
        //c = Serv.substr(Serv.size()-4,50);
        if( a != "com" && a != "net" )   
            { msg_error = 2; }
        else if( a == "com" || a == "net" )
            { msg_error = 0; }
    }  

    //Helper functions....to be not used by the
    //programmer...just inside this header.
    void CheckPort()
    {
	if( Port != 6667 && Port != 6697 )
	    { msg_error = 1; }
        else if( Port == 6667 || Port == 6697 )
            { msg_error = 0; }    
    }
    
    //Helper functions....to be not used by the
    //programmer...just inside this header.
    void WrongPort()
    {
	msg = static_cast<std::string>("Assigned wrong port to the bot.\nPort is: ") + std::to_string(Port) + static_cast<std::string>(".\n");
    }
    
    //Helper functions....to be not used by the
    //programmer...just inside this header. 
    void DomainError()
    {
        msg = static_cast<std::string>("Assigned wrong server to the bot.\nServer is: ") + static_cast<std::string>(Serv) + static_cast<std::string>(".\n"); 
    }

public:
    
    //When using the default one,when you include values by the getter methods
    //put them in a try-catch block.
    Settings_Exception(): Exception() {}
    Settings_Exception(std::string M) : Exception(std::forward<std::string>(M)) {}
    
    //Use only this constructor while initialising with values,else the default
    //one.
    Settings_Exception(std::string serv,std::string chan,unsigned short port) : Exception(), Port(port),Serv(serv) , Chan(chan) 
    {
        CheckPort();  CheckServ();
        Catch();
    }
    
    ~Settings_Exception(void) {}
    const char* what() { return msg.c_str(); }
    
    //Returning functions
    unsigned short rPort() { return Port; }
    std::string rServ() { return Serv; }
    std::string rChan() { return Chan; }
    
    //Main code handling errors
    Settings_Exception Catch()
    {
        Settings_Exception *S;
        switch(msg_error)
        {
          case 0:  break;
          case 1:  WrongPort();
                   S = new Settings_Exception(msg); throw *S; 
                   std::exit(EXIT_FAILURE); 
                   break;
          case 2:  DomainError();
                   S = new Settings_Exception(msg); throw *S;
                   std::exit(EXIT_FAILURE);   
                   break;     
    }
};


I'll post the rest of the code in a min....
Heres the Settings class...

Settings class:-
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <string>
#include <algorithm>
#include "./Settings_Exceptions.hpp"
 
class Settings
    {
private:
        std::string server;
	std::string channel;
	unsigned short port;
	std::string nick;
        Settings_Exception *SE;
        //friend class Config;
 
public:

	Settings() { SE = new Settings_Exception; }
	Settings (Settings &a) : server(a.server), channel(a.channel),
	                         port(a.port), nick(a.nick) 
        {
            try
            {
                SE = new Settings_Exception(a.server,a.channel,a.port);
            }
            catch(Settings_Exception &S)
            {
                std::cout<<"Oops....found an error!!!\n";
                std::cout<<S.what()<<std::endl; 
            }
        }
        Settings(std::string &Serv,std::string &Chan,unsigned short &Port,
           std::string &Nick): server(Serv),channel(Chan),port(Port),nick(Nick)
        {
            try 
            {
                SE = new Settings_Exception(Serv,Chan,Port);
            } 
            catch(Settings_Exception &S)
            {
                std::cout<<"Oops....found an error!!!\n";
                std::cout<<S.what()<<std::endl; 
            } 
        } 
	~Settings() { delete SE; }

	std::string rServer() { return this->server; }
	std::string rChannel() { return this->channel; }
	unsigned short rPort() { return this->port; }
	std::string rNick() { return this->nick; }

	void gServer(std::string &Serv) 
        { 
          server = Serv; 
          try { SE->gServ(server); }
          catch(Settings_Exception &S)
          {
              std::cout<<"Oops....found an error!!!\n";
              std::cout<<S.what()<<std::endl;
          }    
        }
        void gChannel(std::string &Chan) 
        { channel = Chan; SE->gChan(channel); }
        void gPort(unsigned short &Port) 
        { 
          port = Port; 
          try { SE->gPort(port); }
          catch(Settings_Exception &S)
          {
              std::cout<<"Oops....found an error!!!\n";
              std::cout<<S.what()<<std::endl;
          }     
        }
	void gNick(std::string &Nick) { nick = Nick; }

	//Get the data
	inline void getData(std::string &serv,std::string &chan,
			    unsigned short &p,std::string &n)
	{
	    server = serv; channel = chan; port = p; nick = n;
            try
            {
               SE->gServ(server); SE->gChan(channel); SE->gPort(port);
            }
            catch(Settings_Exception &S)
            {
              std::cout<<"Oops....found an error!!!\n";
              std::cout<<S.what()<<std::endl;
            }  
	}
	inline void putData(std::string &serv,std::string &chan,
			    unsigned short &p,std::string &n)
	{
	    serv = server; chan = channel; p = port; n = nick;
	}
        //Compare two strings
	inline bool Compare_To(std::string param1,std::string param2)
	{
	    std::transform(param1.begin(),param1.end(),param1.begin(),
			   std::ptr_fun<int,int>(std::toupper));
	    std::transform(param2.begin(),param2.end(),param2.begin(),
			   std::ptr_fun<int,int>(std::toupper));
	    if( param1.compare(param2) == 0 )
		return true;
	    else if( param1.compare(param2) != 0 )
                return false;
	}
	//Compare two unsigned shorts
	inline bool Compare_To(unsigned short param1,unsigned short param2)
	{
	    if( param1 == param2 )
		return true;
	    else if ( param1 != param2 )
		return false;
	}
	//Clear the contents of the variables
	inline void clear()
	{
	    server.clear();
	    channel.clear();
	    nick.clear();
	    port = 0;
	}
};
Heres the main body of the code where Im getting errors....
The config.cpp source 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "./config.hpp"
#include <fstream>
#include <limits>
#include <exception>

Settings Config :: GetInput()
{
    std::string s,c,n;
    unsigned short p;
    Settings sett;
    std::cout<<"Enter the server IPv4 address:  ";
    std::cin>>s;  std::cout<<"\n";
    std::cout<<"Enter the channel name(eg, #debian ):  ";
    std::cin>>c; std::cout<<"\n";
    std::cout<<"Enter the port to connect to(best: 6667):  ";
    std::cin>>p;std::cout<<"\n";
    std::cout<<"Enter the nickname for that channel:  ";
    std::cin>>n; std::cout<<"\n";
    
    sett.getData(s,c,p,n);

    return sett;
}

void Config :: PutInput(Settings &sett)
{
    std::string s,n,c;
    unsigned short p;
    sett.putData(s,c,p,n);
    std::cout<<"The server IPv4 address is: "<<s<<std::endl
	         <<"The channel name for that server is: "<<c<<std::endl
             <<"The port used to connect is: "<<p<<std::endl
             <<"The nickname for that channel is: "<<n<<std::endl;
}

//----------------------------------------------------------------------------------


Metadata Config:: ReadMetadata()
{

    m_stream.open(meta_file.c_str(), std::ios::in);
    Metadata m;

    try{ m_stream.is_open(); }
    catch(std::ios_base::failure &e)
    { 
        std::cout<<"Found an exception while opening file....\n"
                 <<e.what()<<std::endl;
    }
    if(m_stream.bad())
        throw;
    if(m_stream.fail())
        throw;

    /* Read the data from the meta_file.
       Reason why std::string not used is tht it will through
       away precision when cast from const char* to char and
       char to unsigned int.
    */
    std::string count;
    std::getline(m_stream,count,'\n');
    
    unsigned int coun = std::stoi(count);
    m.gCount(coun);

    m_stream.close();

    return m;
}


//----------------------------------------------------------------------------------


void Config :: WriteMetadata(Metadata &m)
{

    m_stream.open(meta_file.c_str(), std::ios::out);

    try{ m_stream.is_open(); }
    catch(std::ios_base::failure &e)
    { 
        std::cout<<"Found an exception while opening file....\n"
                 <<e.what()<<std::endl; 
    }
    if(m_stream.bad())
        throw;
    if(m_stream.fail())
        throw;

    m_stream<<m.rCount();
    m_stream.flush();

    m_stream.close();
}

//----------------------------------------------------------------------------------

std::streamsize Config :: ReadSize()
{

    m_stream.open(meta_file.c_str(),std::ios::in);
    std::streamsize Size;
    m_stream.ignore(std::numeric_limits<std::streamsize>::max());
    Size = m_stream.gcount();
    m_stream.clear();
    m_stream.seekg(0,std::ios::beg);
    m_stream.close();
    return Size;

}

//------------------------------------------------------------------------------ 


This are the errors I'm getting:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Compiling Config class....
./Src/config.cpp:6:29: error: cannot define member function 
   ‘Settings_Exception::Config::GetInput’ within ‘Settings_Exception
   ’
 Settings Config :: GetInput()
                             ^
./Src/config.cpp:25:39: error: cannot define member function 
   ‘Settings_Exception::Config::PutInput’ within ‘Settings_Exception
   ’
 void Config :: PutInput(Settings &sett)
                                       ^
./Src/config.cpp:39:32: error: cannot define member function 
   ‘Settings_Exception::Config::ReadMetadata’ within ‘
   Settings_Exception’
 Metadata Config:: ReadMetadata()
                                ^
./Src/config.cpp:76:41: error: cannot define member function 
   ‘Settings_Exception::Config::WriteMetadata’ within ‘
   Settings_Exception’
 void Config :: WriteMetadata(Metadata &m)



If you require more parts of the code to help me,I'll give them right away.
Pls help me guys,I am really frustrated going on with this and would appreciate
any help.

Thanks.
If you want to post several files, better upload them to github or similar so it's easier to reproduce your file structure.

cannot define member function 
   ‘Settings_Exception::Config::GetInput’
¿why is `Config' inside `Settings_Exception'?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    //Main code handling errors
    Settings_Exception Catch()
    {
        Settings_Exception *S;
        switch(msg_error)
        {
          case 0:  break;
          case 1:  WrongPort();
                   S = new Settings_Exception(msg); throw *S; 
                   std::exit(EXIT_FAILURE); 
                   break;
          case 2:  DomainError();
                   S = new Settings_Exception(msg); throw *S;
                   std::exit(EXIT_FAILURE);   
                   break;     
    } //this should close the function, but it's closing the switch
}; //this should close the class, but it's closing your function 
you are missing a closing brace there, it would be obvious if you pass your code through an indentation program.


Apart
1
2
3
4
5
           try 
            {
                SE = new Settings_Exception(Serv,Chan,Port);
            } 
            catch(Settings_Exception &S)
¿is there any need to use dynamic allocation there?
Your exception there makes no sense. You tried to construct a `Settings_Exception' object, that failed but throwed a `Settings_Exception' object as an exception. ¿You can't construct it, but you can throw it?
You appear to have mismatched braces {} in that first snippet. Look at this part of that snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    //Main code handling errors
    Settings_Exception Catch()
    {
        Settings_Exception *S;
        switch(msg_error)
        {
          case 0:  break;
          case 1:  WrongPort();
                   S = new Settings_Exception(msg); throw *S; 
                   std::exit(EXIT_FAILURE); 
                   break;
          case 2:  DomainError();
                   S = new Settings_Exception(msg); throw *S;
                   std::exit(EXIT_FAILURE);   
        


Where are the matching braces?

Also where are the include guards for that header?

Lastly using exit() in a C++ program is not really a good idea, this C function doesn't properly call C++ class destructors. And IMO you should only have one statement per line.
Srry guys....this is my first time writing a custom exception class.
I'll upload this files to my github account and reply on more.
Thanks for your eagerness.
Heres my Github repo tht ive made:-

https://github.com/MaBunny/My_IRCbot

It contains all of the files in the project.Thanks for help guys.
Topic archived. No new replies allowed.