It's been a while since I've written in C++, so I've been looking through some old code just to get the beginning of my program started.
I have the following in a file called "branchsim.hpp":
#ifndef _BRANCHSIM_HPP
#define _BRANCHSIM_HPP
// some #include statements here
using std::cin;
using std::cout;
// ... some more using statements here
class BranchSim {
public:
int readMode(&string mode);
};
#endif
and I have this in a file called branchsim.cpp:
#include "./branchsim.hpp"
int main(void) {
string mode;
return EXIT_SUCCESS;
}
/*
* Returns an int representing the branch prediction heuristic to be
used.
*/
int BranchSim::readMode(&string mode) {
switch (tolower(mode)) {
case "at": // always taken
return 1;
case "nt": // never taken
return 2;
case "btfn": // bkwd taken, fwd not taken
return 3;
case "bimodal": // bimodal
return 4;
case "twolevel": // dynamic two level
return 5;
default:
cout << "Invalid prediction mode entered.\n";
}
return 0;
}
and I'm getting the following errors:
./branchsim.cpp:35:24: error: ‘int BranchSim::readMode’ is not a
static data member of ‘class BranchSim’
int BranchSim::readMode(&string mode) {
^
./branchsim.cpp:35:33: error: expected primary-expression before
‘mode’
int BranchSim::readMode(&string mode) {
^
./branchsim.cpp:35:39: error: expected ‘,’ or ‘;’ before ‘{’ token
int BranchSim::readMode(&string mode) {
^
Makefile:16: recipe for target 'branchsim.o' failed
make: *** [branchsim.o] Error 1
I'm just trying to get this to compile so I can continue writing the rest of the program, but am getting stuck.
I believe my syntax is correct..I'm just a bit unsure of how to fix these errors. As I said, my C++ is a bit rusty so this could very well be something quite obvious that I'm missing/forgetting but any help would be greatly appreciated!
EDIT: I'd simply misplaced the & (belongs after string, not before) and I quickly realized c++ doesn't allow switch on strings, so I've adjusted accordingly.
Apologies for the trivial question but thank you for the quick help!
&string
syntax? Secondly, I find it hard to believe that your first error message is as quoted. You should have gotten an earlier error for&string
in your header file.