inherited method was not declared in this scope

I have run into a compilation problem that I cannot figure out, and google hasn't helped me either.
I looked at the output of g++ -E. It didn't enlighten me, but I did copy and paste from that output into a new file. The classes in this file are simplified as much as possible, but compiling this file gives me the same error.

the error is:
linMot-gcc-E.cc: In function ‘MOTION_TYPE getMotionType()’:
linMot-gcc-E.cc:47: error: ‘clMatch’ was not declared in this scope


$ g++ --version
g++ (Debian 4.3.4-5) 4.3.4


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//save as linMot-gcc-E.cc

/* created from the output of g++ -E:
g++ -E -c -pipe -m64 -g -Wall -W -D_REENTRANT -fPIC -DLIN -DLININTEL -D_OCC64 -DHAVE_CONFIG_H -DHAVE_IOSTREAM \
-DHAVE_FSTREAM -DHAVE_LIMITS -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. \
-I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/opt/occ63/inc -I../uio \
-I/usr/X11R6/include -I/usr/X11R6/include -I.moc -o linearMotion.E linearMotion.cc
*/

//compile: g++ -c -pipe -m64 -g -Wall -W -D_REENTRANT -fPIC -I.moc -o linMotE.O linMot-gcc-E.cc

#include <string>

typedef int machineStatus;

class canonLine {
  protected:
    canonLine(std::string canonL, machineStatus prevStatus);
    bool clMatch(std::string m);
};
//# 13 "canonMotion.hh" 2


typedef enum { HELICAL, LINEAR, RAPID } MOTION_TYPE;

class canonMotion: protected canonLine {
  public:
    virtual MOTION_TYPE getMotionType() = 0;
  protected:
    canonMotion(std::string canonL, machineStatus prevStatus);
};
//# 10 "linearMotion.hh" 2


class linearMotion: protected canonMotion {
  public:
    linearMotion(std::string canonL, machineStatus prevStatus);
};
//# 4 "linearMotion.cc" 2


linearMotion::linearMotion(std::string canonL, machineStatus prevStatus): canonMotion(canonL,prevStatus) {
}


MOTION_TYPE getMotionType() {
  static bool rapid = clMatch("LINEAR_TRAVERSE");
  if (rapid)
    return RAPID;
  else
    return LINEAR;
};


What am I doing wrong?
Thanks
Mark
Last edited on
You need to tell it you are defining canonMotion's getMotionType(), and not a new global function:

1
2
3
MOTION_TYPE canonMotion::getMotionType() {
//...
} //FYI you don't need the ';' here 
Firedraco, thanks for the help!

I now have
1
2
3
4
5
class linearMotion: protected canonMotion {
  public:
    linearMotion(std::string canonL, machineStatus prevStatus);
    MOTION_TYPE getMotionType();
};
in the header file, and
1
2
3
MOTION_TYPE linearMotion::getMotionType() {
...
}
in the implementation file.

It never occurred to me that the function I was within could be the problem. :-/
Also, I didn't know that I had to declare virtual methods in the header of the derived class.
Topic archived. No new replies allowed.