472,976 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Cannot call member function without object

I am trying to pass uid and pwd to the function CheckPW of the class PWServer.
I receive the error pwclient.cpp:41: error: cannot call member function âint PWServer::CheckPW(const char*, char*)â without object
Where am I going wrong?

Here is the code in int main():
cout << "User ID: ";
cin >> uid;
cout << "Password: ";
cin >> pwd;
PWServer::CheckPW (uid, pwd)
Oct 5 '09 #1
10 15907
whodgson
542 512MB
Can`t see anything wrong with that snippet ---probably need to post more code.
Oct 5 '09 #2
#include <xstring.h>
#include <pwserver.h>
#include <iostream>
#include <istream>
using namespace std;
using std::cin;
using std::cout;
using std::endl;

char choice;
char* user;
char* password;

int main ()
{
cout << "Make selections using the following menu:" << endl;
cout << "Check Password (uid, upw) 1" << endl;
cout << "Change Password (uid, upw, npw) 2" << endl;
cout << "Create New User (uid, upw) 3" << endl;
cout << "Delete User (uid) 4" << endl;
cout << "Dump () d" << endl;
cout << "Display Output File f" << endl;
cout << "Display main (this) menu m" << endl;
cout << "Quit q" << endl;

do
{
cout << "Enter choice: ";
cin >> choice;
switch (choice)
{
case '1':
cout << "User ID: ";
cin >> user;
cout << "Password: ";
cin >> password;
PWServer::CheckPW(user, password);
Oct 5 '09 #3
whodgson
542 512MB
So the PWserver class is declared in pwserver.h--- is this correct? If so where is the PWServer class definition which includes its methods and data.?
Oct 5 '09 #4
Yes, PWServer is declared in pwserver.h.
PWServer methods and data for my first problem
int CheckPW (const char* uid, char* upw);
takes the user id (uid) and password (pwd) and checks its validity and returns 1 if valid and 0 if not valid
Oct 5 '09 #5
Here is the code for PWServer:
class PWServer
{
public:
// constructors
PWServer (const char* infile, const char* outfile, unsigned int max);
~PWServer ();

// password services

int CheckPW (const char* uid, char* upw);
// return 1 iff the signature matches the user id

int ChangePW (const char* uid, char* upw, char* newpw);
// return 1 iff user signature is successfully updated

int CreateUser (const char* uid, char* upw);
// return 1 iff new user,signature is successfully inserted and file updated

int DeleteUser (const char* uid);
// return 1 iff user is sucessfully deleted and file updated

void Dump(std::ostream& out1 = std::cout);
// public during white-box testing, then privatized
Oct 5 '09 #6
What if you instantiate a PWServer using new?

Or I think you could change your PWServer class to make the CheckPW() function "static," but that may not be a good design...
Oct 5 '09 #7
How would I do that? This is my first progamming class with C++
Oct 5 '09 #8
PWServer pws = new PWServer(infile,outfile,max);
you will need to substitute your appropriate values for infile, outfile, and max depending on how you've defined them.

if(pws.CheckPW(uid,upw) == 1) -or whatever is appropriate
again you'll need to fill in the appropriate values for uid and upw depending on how you defined them. You'll need to put it into some kind of conditional statement to check if the value is 1 or not.
Oct 5 '09 #9
Banfa
9,065 Expert Mod 8TB
randysimes, the basic problem is that you have declared the class PWServer but you never instantiated an object of that class.

It is important to understand the difference between a class definition and an instantiation because you can not call class methods via the class name, you have to call them via an object of the class, unless the methods are static class methods.

JonathanS has suggested 1 method of instantiating a class using the new operator. If you use this method remember to delete the object when you have finished with it or you will get a memory leak. Also he has his syntax slightly wrong it should be

Expand|Select|Wrap|Line Numbers
  1.     PWServer *pws = new PWServer(infile,outfile,max);
  2.  
  3.     /* Code using pws */
  4.  
  5.     delete pws;
  6.  
Another method would be to just declare the object on the stack, the compiler will handle deleting the object but it will only exist for the lifetime of the function it is declared in.

Expand|Select|Wrap|Line Numbers
  1.     PWServer pws(infile,outfile,max);
  2.  
  3.     /* Code using pws */
  4.  
Oct 5 '09 #10
That was my bad Randy. Thanks for straightening it out Banfa.
Oct 5 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: christopher vogt | last post by:
Hi, i'm wondering if there is something like $this-> to call a method inside another method of the same class without using the classname in front. I actually use class TEST { function...
27
by: Jason Shohet | last post by:
I have an ascx control, and it needs a value called 'orgID' which the parent page will have. I want to avoid the parent page setting values in fields on the ascx control since this violates...
26
by: Martin Jørgensen | last post by:
Hi, I don't understand these errors I get: g++ Persort.cpp Persort.cpp: In function 'int main()': Persort.cpp:43: error: name lookup of 'j' changed for new ISO 'for' scoping Persort.cpp:37:...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
5
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions...
2
by: Elliott | last post by:
Hello Everyone, I have a function in a header (KeyDialog.h) as such: void setKey(Key&); The function implementation is as such (KeyDialog.cpp): void KeyDialog::setKey(Key& k1) {
4
by: viki | last post by:
We have zillion of instances inf instance->m_member in the code. We are going introduce the 'accessors' Get() and Set() for m_member, and m_member going private (and renamed, too). We would like...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.