Question about constructors ...

A

Andrew

Is it possible a constructor of a class to use a funtion defined in
the same class ????
 
V

Victor Bazarov

Andrew said:
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
 
A

Andrew

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=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
 
D

David White

Andrew said:
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
 

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,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top