473,406 Members | 2,956 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,406 software developers and data experts.

Question about constructors ...

Is it possible a constructor of a class to use a funtion defined in
the same class ????
Jul 22 '05 #1
4 1237

"Andrew" <af********************@yahoo.com> wrote in message news:3p********************************@4ax.com...
Is it possible a constructor of a class to use a funtion defined in
the same class ????


Certainly.
Jul 22 '05 #2
"Andrew" <af********************@yahoo.com> wrote...
Is it possible a constructor of a class to use a funtion defined in
the same class ????


Yes.

Do you have a problem with your code? Follow the recommendations in
FAQ 5.8.

Victor
Jul 22 '05 #3
On Tue, 09 Dec 2003 18:11:35 GMT, "Victor Bazarov"
<v.********@comAcast.net> wrote:
"Andrew" <af********************@yahoo.com> wrote...
Is it possible a constructor of a class to use a funtion defined in
the same class ????


Yes.

Do you have a problem with your code? Follow the recommendations in
FAQ 5.8.

Victor


Ok ... I do not receive error from the compiler but from the linker .
I am using Visual C++

Here is my code (HTTPClient is another class , and String is my own
string class )

#include "HTTPClient.h"
#ifndef _GET_USERNAME_STRING
#define _GET_USERNAME_STRING 0
#endif
#ifndef _GET_PASSWORD_STRING
#define _GET_PASSWORD_STRING 1
#endif

#ifndef _GET_IP_STRING
#define _GET_IP_STRING 2
#endif
class AP : public HTTPClient
{
public:

// Constructors and Destructors .....

AP(); // <-- Where
no parameters are passed ....
AP(String,String,String); // <-- Where all of the
parameters are passed .
AP(String); // <-- Where only the ip address
is passed
~AP();

// Accessors ...

void GetApInfo(void); // should that called
from the constructor ??
void GetApStatistics(int); // int paramter ????
String PromptUserForInput(unsigned short); // another parameter ?
exactly !!
void ApSet_Channel(unsigned short);
int ApGet_Channel(void);
String ApGet_SSID(void);
String ApGet_SubnetMask(void);
void ApSet_SubnetMask(String);
String ApSet_MACAddress(void);
void ApSet_MACAddress(String);
String ApGet_EncryptionMethod(void);
void ApSet_EncryptionMethod(String);
// protected members ..

protected:

String Ap_ip;
String Ap_usrnam;
String Ap_passwd;
// private members ...

private:

String MAC_Address;
bool Ap_Encryption_Function;
int Ap_Channel; //needs somehow casting ...
!!
String Ap_SSID;
String Ap_SubnetMask;
String Ap_GetAway;
String Ap_Mode;
String Ap_DHCP_Mode;

// for the main program , to distinguish access points between
them

unsigned short Ap_ID;
// What should i put here ????

};

// Default constructor , used when you have not pass any of the three
required para

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

// What should that do ??

}

AP::AP(String 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)
{
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);
}
}


// function to be replaced with the onStream operator

String PromptUserForInput(unsigned short param)
{
String tempString(20);
char c;
int i=0;
switch(param)
{
case _GET_USERNAME_STRING:
{
cout << "Please enter your username\n" ;
break;
}
case _GET_PASSWORD_STRING:
{
cout << "Please enter your password\n" ;
break;
}
case _GET_IP_STRING:
{
cout << "Please Give me the Ip Address of the
Access Point \n" ;
break;
}
default:
{
cout << "Error(Non Fatal) Wrong parameter to
AP::PromptUserForInput \n" ;
exit(EXIT_FAILURE);

// return ???
}
}
while( (c=getchar()) !='\n')
{
tempString[i]=c;
i++;
}
return tempString;
}

int main(void)
{
AP Dlink();
cout << "Hello world .... \n" ;
return 0;
}
The problem is with the PromptUserForInput .... The compilation does
not generate any errors but the linker complains about the following :
FinalCpp.obj : error LNK2001: unresolved external symbol "public:
class String __thiscall AP::PromptUserForInput(unsigned short)"
(?PromptUserForInput@AP@@QAE?AVString@@G@Z)
Debug/FinalCpp.exe : fatal error LNK1120: 1 unresolved externals

Jul 22 '05 #4
"Andrew" <af********************@yahoo.com> wrote in message
news:sg********************************@4ax.com...
On Tue, 09 Dec 2003 18:11:35 GMT, "Victor Bazarov"
<v.********@comAcast.net> wrote:
"Andrew" <af********************@yahoo.com> wrote...
Is it possible a constructor of a class to use a funtion defined in
the same class ????
Yes.

Do you have a problem with your code? Follow the recommendations in
FAQ 5.8.

Victor


Ok ... I do not receive error from the compiler but from the linker .
I am using Visual C++

Here is my code (HTTPClient is another class , and String is my own
string class )


[snip]
class AP : public HTTPClient
{
public:
[snip]
String PromptUserForInput(unsigned short);
[snip]
};
[snip]
String PromptUserForInput(unsigned short param)
{
You have defined this external function PromptUserForInput, but you have not
defined the member function AP::PromptUserForInput, which is why the linker
is complaining.

[snip]
FinalCpp.obj : error LNK2001: unresolved external symbol "public:
class String __thiscall AP::PromptUserForInput(unsigned short)"


[snip]

DW

Jul 22 '05 #5

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

Similar topics

6
by: Sean Dettrick | last post by:
Hi, I have a class which I want everything to have access to, and which I only want to construct once. I have a hierarchy of classes: class ScalarField{ vector<double> f; // constructors etc...
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...
6
by: z_learning_tester | last post by:
Quick question- What happens if you have a private class with a public static method? Can you still say the following? Lets say you are making this call from another class, say class2... int...
10
by: Kevin Buchan | last post by:
I searched the news group and could not find an answer to this question, so I'll go ahead and post it. Let's say I have a class A with a couple different constructors... nothin' special. Now,...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
12
by: Oleg Subachev | last post by:
I am moving from Delphi to C# and hve encountered the problem: I have the following classes and form Load event handler: public class class1 { public string S; public class1( string aS ) {...
31
by: cctv.star | last post by:
I was wondering, why you always have to remember to call bases' constructors explicitly from the derived class constructor? Why hasn't this been enforced by the language?
5
by: Dom | last post by:
is there a difference between the following: Rectangle r = new Rectangle (10,20,30,40); Rectangle r = Rectangle.FromLTRB(10,20,30,40); Also, I guess I'm not sure why Structs are created with a...
5
by: bz | last post by:
Hi, I have a base class with several constructors and I want to create a derived class, as below class MyBase { public MyBase() {...} public MyBase(int ID) {...} public MyBase(string...
2
by: Greg | last post by:
Hi, I have a class that has 3 different constructors in it. In the base constructor I want to have it set some default data. I don't want to have the overloaded constructors do these same...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.