473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Questions about constructors

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 .
Jul 22 '05 #1
1 963
AP AP1(); This is a declaration of a function called AP1, taking no args and returning
an AP.
AP AP1 // with no "()"


This is an instance of an AP named AP1.

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
4
by: Busin | last post by:
When a child class inherits from a base class, will the child class inherits everything of the base class, including all member variables and functions? Or is such inheritance "selective", like not...
14
by: MSR | last post by:
I have a couple of questions. 1. Copy Constructor. class A { private: int a1; double d1; char *ptr;
12
by: Sashi | last post by:
All, I had an interview today and I couldn't answer these questions. Any good answers? Why does a copy constructor param need to be const? Ever need a virtual constructor? Major difference...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
7
by: Michael | last post by:
Hi, I have a few questions here. 1. Is there a way to go from the sub-classes (one or more layers) to the base class directly? 2. What's the sequence of executing constructors function and...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
3
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.