By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

Question about constructors ...

P: n/a
Is it possible a constructor of a class to use a funtion defined in
the same class ????
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"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

P: n/a
"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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.