Questions about constructors

A

Andrew

I have created a class named AP which has the following 3 constructors
:

.............

AP::AP()
{
cout << "Default Constructor called ... \n" ;

// What should that do ??

}


// AP::AP(String ip) NOT WORKING !!!!!!!!!!!1


AP::AP(String ip)
{

Ap_ip=ip;

cout << " Needed authorization to proceed \n";

//Ap_usrnam=PromptUserForInput(_GET_USERNAME_STRING);
//Ap_passwd=PromptUserForInput(_GET_PASSWORD_STRING);

if ( (strcmp(Ap_usrnam.GetString()," ") ==0) ||
(strcmp(Ap_passwd.GetString()," ")==0))
{
cout << "Error(Non Fatal) You did not entered one of
the two fields \n";
exit(EXIT_FAILURE);
}

}


AP::AP(String ip,String usernam,String pass)
{
// cout << "Constructor with 3 parameters found ..... \n";
Ap_ip=ip;
Ap_usrnam=usernam;
Ap_passwd=pass;


if ( (strcmp(Ap_usrnam.GetString(),"") ==0) ||
(strcmp(Ap_passwd.GetString(),"")==0))
{
cout << "Error(Non Fatal) You did not entered one of
the two fields \n";
exit(EXIT_FAILURE);
}

GetApInfo();
}

.. Suppose now i want to create an object of the class Access Point
using the first constructor (which takes no parameters ) . I then
write :

AP AP1();

Fine . Now i want to call a function declared inside the AP class ,
GetAPInfo(). I type something like that :

AP1.GetApInfo();

but the compiler complains with the following error :

C:\Documents and Settings\root\My
Documents\#Diplomatikh\#C\Problem.cpp(14) : error C2228: left of
'.SetIpAddress' must have class/struct/union type

.. I now change the statement AP AP1() to

AP AP1 // with no "()"

The program compiles fine and everything is great now . However both
declerations call the default constructor and i cannot understand what
is the problem .

More questions . I decide to create an AP object using the third
constructor (with 3 parameters ) . It looks like this :

AP AP1(ip,username,password) // ip ,username , password are
objects of the String class written by myself

I call now the same function :

AP1.GetIPinfo()

and again everything works great !! Why ??? . What is the problem with
the decleration AP AP1() ???? . I won't post the whole code because
it's 1000+ lines )

Sorry for my English .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,405
Latest member
DavidCex

Latest Threads

Top