Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6930993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:31:11+00:00 2026-05-27T11:31:11+00:00

I am currently teaching myself C++ using A C++ for Dummies All-In-One; second edition.

  • 0

I am currently teaching myself C++ using A C++ for Dummies All-In-One; second edition. TO create this program I am using Qt. I understand it to be a good practice to organize objects and classes in your header files and prospectively your member functions in a .cpp file built in addition to the main.cpp. In this regard I try to run the exercises in this book as such but just recently encountered the following error.

expected primary-expression before '.' token

This error occurs on Lines 31, 32, and 37 so they appear to be relevant to my class member functions specifically.

My main.cpp

#include "controlinginput.h"
#include <QtCore/QCoreApplication>
#include <iostream>
#include <sstream>


using namespace std;

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);


// just a basic name-entering
string name;
cout << "What is your name?";
cin >> name;
cout << "Hello " << name << endl;

/* now you are asked for a number
  but the computer will allow you to enter anything*/
int x;
cout << endl << "Enter a number! Any Number!" << endl;
cin >> x;
cout << "You choose " << x << endl;

/* now youll be asked for a number again
  but the computer will only allow numbers */
cout << endl<< "This time you will ONLY be able to enter a number! " << endl;
cout << "SO, Pick a number! any number!" << endl;
string entered = ControlingInput.enterOnlyNumbers(); // ###Error###        
int num = ControlingInput.stringToANumber(entered); // ###Error###
cout << endl << "You entered " << num << endl; // value is displayed
//Now finally we enter the password
cout << endl;
cout << "Please enter a password" << endl;
string password = ControlingInput.EnterPassword(); // ###Error###
cout << "shh... your password is " << password << endl;
return a.exec();
}

I did some research to find that this error indicates a pretty broad range of misuse of syntax. Unfortunately I was unable to find an instance that resembled mine specifically; I was hoping to get some insight from some of the more experienced programmers. If this is a simple issue that is on account of negligence on my end I apologize in advance and appreciate the feedback. I learn better if it gave me allot of trouble as opposed to a little..

Because these include my member functions I have also included my header file and .cpp

controlingInput.cpp (I have included my header file and iostream and sstream here but for some reason the editor was giving me problems on here)

using namespace std;

ControlingInput::ControlingInput()
{

}
int ControlingInput::stringToANumber(string MyString)
{
istringstream converter(MyString); //Holds the string that was passed to this function
int result;                        //Holds the integer result

//perform the conversion
converter >> result;
return result; //function completes and returns converted string

}

string ControlingInput::enterOnlyNumbers()
{
string numbAsString = ""; // this holds our numeric string
        char ch = getch();  // This gets a single character from our user
//Says to keep gettting characters from our user untill user presses enter
        while (ch != '\r') // \r is the enter key
        {
           //This says to add characters only if they are numbers
            if (ch >= '0' && ch <='9')
            {
                cout << ch; // show
                numbAsString += ch; // add character to the string
            }

            ch = getch(); // get the next character from the user

        }
        return numbAsString;

}

string ControlingInput::EnterPassword()
{
string numbAsString = ""; //this will hold our password string
char ch = getch(); // this gets a single char from our users just like before
//keep gettting characters from the user until enter/return is pressed
while (ch != '\r'); // \r is the enter or return key
{
    //for security passwords are displayed as asterisks instead of characters
    cout << '*';

    //add character input into the password string
    numbAsString += ch;

    //Get the next character from the user
    ch = getch();
}
return numbAsString; // return the user input from this function

And Here is my controlingInput.h

#ifndef CONTROLINGINPUT_H
#define CONTROLINGINPUT_H
#include <iostream>

using namespace std;

class ControlingInput
{
public:
int stringToANumber(string MyString);
string EnterPassword();
string enterOnlyNumbers();

};

#endif // CONTROLINGINPUT_H

Thanks in advance for any feedback.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:31:12+00:00Added an answer on May 27, 2026 at 11:31 am

    You are attempting to call instance variables with the class itself as if they were static (which would still be invalid syntax). For this to work properly you need an instance of ControlingInput.

    int main(int argc, char *argv[])
    {
    
        QCoreApplication a(argc, argv);
    
        ControlingInput ctrlInput; //Create instance
        ...
    
        string entered = ctrlInput.enterOnlyNumbers();        
        int num = ctrlInput.stringToANumber(entered);
        cout << endl << "You entered " << num << endl; // value is displayed
        ...
    
        string password = ctrlInput.EnterPassword();
        cout << "shh... your password is " << password << endl;
        return a.exec();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently teaching myself Objective-C and Iphone Development using the very good 'Begining IPhone
Hey all, I'm currently teaching myself Objective C and I'm kind of stuck. I'm
I am currently teaching myself about various data strutures and am a little frustrated
I've been teaching myself functional programming, and I'm currently writing different higher order functions
I'm currently teaching myself objective C. I've gone through the tutorials, but I find
I have been teaching myself OpenGL programming using the Python wrapper PyOpenGL, and am
I am currently teaching myself iPhone programming and working on solving assignment 2 [PDF]
I'm interested in teaching myself different data structures, something I currently know very little
I am teaching myself Android using Eclipse, the Android plug-in, and Sams Teach Yourself
I'm currently teaching myself Python and was just wondering (In reference to my example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.