Article 5BZW6 [SOLVED] typedef error

[SOLVED] typedef error

by
maschelsea
from LinuxQuestions.org on (#5BZW6)
I am working through Sams Teach Yourself C++ in 21 Days. I am currently on Day 14. I've typed in listing14.9 and I can't get it to compile. I am not comfortable with typedefs in general, never having used them in either class or practice. The following listing uses a typedef and I think it's confusing me more than anything else in this program.
Code:michael@caitlyn 14 $ cat listing14.9.cpp
//Listing 14.9 - using typedef to make pointers to functions more readable
//2020-12-22
#include <iostream>

void Square(int&, int&);
void Cube(int&, int&);
void Swap(int&, int&);
void GetVals(int&, int&);
typedef void (*VPF)(int&, int&);
void PrintVals(int&, int&);

int main()
{
int valOne=1, valTwo=2;
int choice;
bool fQuit = false;
VFP pFunc;
while (fQuit == false) //while (!fQuit)
{
std::cout << "(0)Quit, (1)Change values, (2)Square, (3)Cube, (4)Swap: ";
std::cin >> choice;
switch (choice)
{
case 1: pFunc = GetVals; break;
case 2: pFunc = Square; break;
case 3: pFunc = Cube; break;
case 4: pFunc = Swap; break;
default: fQuit = true; break;
}
if (fQuit == true) break; //if (fQuit)
PrintVals(pFunc, valOne, valTwo);
}
return 0;
}

void PrintVals(VPF pFunc, int&x, int& y)
{
std::cout << "x: " << x << " y: " << y << std::endl;
pFunc(x, y);
std::cout << "x: " << x << " y: " << y << std::endl;
}

void Square(int &rX, int &rY)
{
rX*=rX;
rY*=rY;
}

void Cube(int& rX, int& rY)
{
int tmp = rX;
rX*=rX;
rX = rX * tmp;

tmp=rY;
rY*=rY;
rY = rY * tmp;
}

void Swap(int& rX, int& rY)
{
int temp = rX;
rX = rY;
rY = temp;
}

void GetVals(int& rValOne, int& rValTwo)
{
std::cout << "New value for valOne: ";
std::cin >> rValOne;
std::cout << "New value for valTwo: ";
std::cin >> rValTwo;
}And the error log:

Code:michael@caitlyn 14 $ g++ listing14.9.cpp -o listing14.9
listing14.9.cpp: In function 'int main()':
listing14.9.cpp:17:4: error: 'VFP' was not declared in this scope
VFP pFunc;
^
listing14.9.cpp:24:12: error: 'pFunc' was not declared in this scope
case 1: pFunc = GetVals; break;
^
listing14.9.cpp:31:17: error: 'pFunc' was not declared in this scope
PrintVals(pFunc, valOne, valTwo);
^The book has said (numerous times it feels like) that whitespace doesn't matter to g++. Each of the three errors above seem to lead back to my typedef. I want to understand every listing in that book. What exactly am I doing wrong in this program, and how to I fix it? Thank you in advance to anyone willing to assist me on this.latest?d=yIl2AUoC8zA latest?i=K8BB77Yjyec:1xTtSdD4kD0:F7zBnMy latest?i=K8BB77Yjyec:1xTtSdD4kD0:V_sGLiP latest?d=qj6IDK7rITs latest?i=K8BB77Yjyec:1xTtSdD4kD0:gIN9vFwK8BB77Yjyec
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments