I am currently teaching C ++ using A C ++ for All-In-One dummies; second edition. To create this program, I use Qt. I understand that it is good practice to organize objects and classes in your header files and your prospective member functions in a .cpp file built in addition to main.cpp. In this regard, I am trying to start the exercises in this book as such, but only recently encountered the following error.
expected primary-expression before '.' token
This error occurs on lines 31, 32, and 37, so they seem to relate to my class member functions.
My main.cpp
#include "controlinginput.h"
I did some research to find that this error indicates a fairly wide range of syntax abuse. Unfortunately, I could not find an instance similar to mine; I was hoping to get some insights from some more experienced programmers. If this is a simple negligence problem at my end, I apologize in advance and appreciate the feedback. Iād better know if he gave me trouble, not a bit.
Since they include my member functions, I also included my header file and .cpp
controlingInput.cpp (I included my header file and iostream and sstream here, but for some reason the editor was asking me problems 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 control
#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.
source share