error: Type expected class-name before ‘{’ token

Steven Tuckness (3)
I have googled this to quite a bit...and I'm just not understanding the problem. I have header guards...I tried forward declarations...(which I don't fully understand yet, but that doesn't FEEL like the anwser..maybe I'm wrong. I've put a great deal of hours into this...any assistance or suggestion greatly appreciated. Thanks.

Here is my Sound.h.

I continue to get the error "Type expected class-name before ‘{’ token" right where I'm trying to use Element as a base class...

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
#ifndef SOUND_H_
#define SOUND_H_

#include <fruitpunch/Elements/Element.h>
#include <boost/shared_ptr.hpp>
#include <vector>
#include "string"

namespace fpunch {

class Sound : public Element {
public:
	Sound();
	Sound(std::string);
	void play();
	void stop();
	virtual void renderFrame();

private:
	boost::shared_ptr<std::vector<char> > 	mData;
	int 									mFreq;
	int 									mChannels;
	int										mInstanceId;
	bool 									mIsPlaying;
	bool									mIsLoop;
}; // end class Sound

} // end namespace fpunch
#endif /*SOUND_H_ */ 


here is Element.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef ELEMENT_H_
#define ELEMENT_H_

#include <boost/shared_ptr.hpp>
#include <fruitpunch/Elements/Scene.h>

namespace fpunch {

class Element {
public:
  Element();
  virtual void renderFrame() =0;
  boost::shared_ptr<Scene> getScene() const;
  void setScene(boost::shared_ptr<Scene> scene);

  virtual void onAdd() =0;
  virtual void onRemove() =0;
private:
  boost::shared_ptr<Scene> mScene;
};

} /* namespace fpunch */
#endif /* ELEMENT_H_ */ 
kbw (5375)
It can't see the definition of Element.

Just some observations.
1. You own project files should not be included with <>
2. Element is an abstract base class, but doesn't have a virtual destructor.
Steven Tuckness (3)
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
#ifndef SOUND_H_
#define SOUND_H_

#include "fruitpunch/Elements/Element.h"
#include <boost/shared_ptr.hpp>
#include <vector>
#include "string"

namespace fpunch {

class Sound : public Element {
public:
	Sound();
	Sound(std::string);
	void play();
	void stop();
	virtual void renderFrame();
	virtual ~Sound();

private:
	boost::shared_ptr<std::vector<char> > 	mData;
	int 									mFreq;
	int 									mChannels;
	int										mInstanceId;
	bool 									mIsPlaying;
	bool									mIsLoop;
}; // end class Sound

} // end namespace fpunch
#endif /*SOUND_H_ */ 


I'm wondering why it can't see see the definition of Element... This other class can see Element just fine...I will make a note that my project files should not be in <> thank you.

The playable class works well extending from Element...which is why I keep thinking I've done something wrong in the Sound class somewhere...Of course I could be mistaken...


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
#ifndef PLAYABLE_H_
#define PLAYABLE_H_

#include <fruitpunch/Elements/Element.h>

namespace fpunch {

class Playable : public Element {
public:
  Playable();
  void start();
  void stop();
  virtual void renderFrame();
  virtual void renderSingle(int frame) =0;
  virtual int calculateDuration() const =0;
  virtual ~Playable();
  int getCurrentFrame() const;
  void setCurrentFrame(int currentFrame);
  bool isPlaying() const;
  void setPlaying(bool isPlaying);
  bool isLoop() const;
  void setLoop(bool loop);
  int getStartFrame() const;
  void setStartFrame(int startFrame);
  int getEndFrame() const;

  virtual void onAdd();
  virtual void onRemove();


private:
  int mCurrentFrame;
  int mStartFrame;
  bool mLoop;
  bool mIsPlaying;
};

} /* namespace fpunch */
#endif /* PLAYABLE_H_ */ 


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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Playable.cpp
 *
 *  Created on: May 10, 2012
 *      Author: leo
 */

#include <fruitpunch/Elements/Playable.h>

namespace fpunch {

Playable::Playable() {
  mCurrentFrame = 0;
  mStartFrame = 0;
}

Playable::~Playable() {
  // TODO Auto-generated destructor stub
}

void Playable::start() {
  mIsPlaying = true;
}

void Playable::stop() {
  mIsPlaying = false;
}

void Playable::renderFrame() {
  if (!mIsPlaying) return;
  renderSingle(mCurrentFrame);
  mCurrentFrame++;

  // If we reached the end of the animation, go back to frame zero.
  // Only stop playing if looping is not enabled
  if (mCurrentFrame > calculateDuration()) {
    mCurrentFrame = 0;
    if (!mLoop) stop();
  }
}

int Playable::getCurrentFrame() const {
  return mCurrentFrame;
}

void Playable::setCurrentFrame(int currentFrame) {
  mCurrentFrame = currentFrame;
}

bool Playable::isPlaying() const {
  return mIsPlaying;
}

void Playable::setPlaying(bool isPlaying) {
  mIsPlaying = isPlaying;
}

bool Playable::isLoop() const {
  return mLoop;
}

void Playable::setLoop(bool loop) {
  mLoop = loop;
}

int Playable::getStartFrame() const {
  return mStartFrame;
}

void Playable::setStartFrame(int startFrame) {
  mStartFrame = startFrame;
}

int Playable::getEndFrame() const {
  return mStartFrame + calculateDuration() - 1;
}

void Playable::onAdd() {
}

void Playable::onRemove() {
}


}/* namespace fpunch */

kbw (5375)
You could run the pre-processor and check the output. This way you can confirm what the compiler sees.
Steven Tuckness (3)
kbw...Is this easy to do with cmake?

Anyway the problem ended up being that I messed a few of the other like 8 classes that I added. A tricky circular include was one problem. The problems in the other classes caused an issue with this class to not compile correctly.
Topic archived. No new replies allowed.