Error: ISO C++ forbids declaration [className] with no type

i have two similar errors which i cannot fix. i have made both classes Model and ModelChangeQueue from the same template as the other classes which are not throwing errors.

ModelChange.h:34: error: ISO C++ forbids declaration of ‘Model’ with no type
ModelChange.h:34: error: expected ‘;’ before ‘*’ token

refers to

  
Model *model;  

in ModelChange.h

and

ModelController.h:52: error: ISO C++ forbids declaration of ‘ModelChangeQueue’ with no type
ModelController.h:52: error: expected ‘;’ before ‘*’ token

refer to

  
ModelChangeQueue *modelChnageQueue;  

in ModelController.h

here is the .h and .ccp code for the ModelChangeQueue because it is has much less than the Model class.

ModelChangeQueue.h

  
  
#ifndef _MODEL_CHANGE_QUEUE  
#define _MODEL_CHANGE_QUEUE  
  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
#include "ModelChange.h"  
  
#include <map>  
  
class ModelChangeQueue {  
	public:  
		ModelChangeQueue();  
		ModelChangeQueue(const ModelChangeQueue&);  
		  
		void start();  
		void pause();  
		void stop();  
		  
		void add(ModelChange imodelChange);  
		void add(vector<ModelChange*> imodelChanges);  
		  
		void update();  
   
		int modelChangesIndex;  
   
		vector<ModelChange*> modelChanges;  
};  
  
#endif  
  

ModelChangeQueue.cpp

  
  
#include "ModelChangeQueue.h"  
  
ModelChangeQueue::ModelChangeQueue() {   
	modelChangesIndex = 0;  
}  
  
void ModelChangeQueue::update() {  
	if(!modelChanges(modelChangesIndex).isChanging) {  
		modelChangesIndex++;  
		modelChanges(modelChangesIndex).start();  
	}  
}  
  
void ModelChangeQueue::add(ModelChange imodelChange) {  
	modelChanges.push_back(imodelChange);  
}  
  
void ModelChangeQueue::start() {  
	modelChanges(modelChangesIndex).start();  
}  
  
void ModelChangeQueue::pause() { }  
  
void ModelChangeQueue::stop() { }  
  

thanks!

Hey,

Did you add

  
  
#include "ModelChange.h"  
#include "ModelChangeQueue.h"  
  

at the top of the header file which uses these objects?

Every time I get that error, that’s what it is :slight_smile:

that is what i would think also but i did include ModelChange.h in ModleChangeQueue.h as seen in the ModelChangeQueue.h code i posted before.

Can you post both the other header files?
This error can happen if you copy and past the same:

  
#ifndef _MODEL_CHANGE_QUEUE   
#define _MODEL_CHANGE_QUEUE   

at the top of every file.
I have done this a lot and it can a while to figure out - then you kick yourself! :smiley:

an alternative to the

  
#ifndef _MODEL_CHANGE_QUEUE   
#define _MODEL_CHANGE_QUEUE   
  
.....  
  
#endif;  
  

is just to put

  
#pragma once   

at the top of the file - with no #endif at the bottom

This has the same effect and you don’t have to worry about the #defines you choose conflicting with any other defines.

Theo

thanks theo, but that didnt fix the error here are the new errors and header files.

the new error is
ModelChange.h:19: error: expected `)’ before ‘imodel’
ModelChange.h:34: error: ‘Model’ does not name a type

the ModelChange.h code is

  
  
#pragma once  
  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
#include "Model.h"  
  
class ModelChange {  
	public:  
		ModelChange(Model imodel, string itop, string ibottom, string istate, string idirection, float idelay);  
		ModelChange(const ModelChange&);  
		ModelChange();  
		  
		void start();  
		  
		string top;   
		string bottom;   
		string state;   
		string direction;   
		  
		string movie;  
		  
		float  delay;  
		  
		Model model;  
		ModelConstants *modelConstants;  
};  
  

and the Model.h code is

  
  
#pragma once  
  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
#include "ModelChange.h"  
  
#include "Movies.h"  
  
class Model {  
	public:  
		Model(string iid, int ix, int iy, string itop, string ibottom, string istate, string idirection, string imodelToLeft, string imodelToRight);   
		Model(const Model&);  
		Model();  
		  
		void setup(string iid, int ix, int iy, string itop, string ibottom, string istate, string idirection);  
		void draw();  
		void update();  
		  
		vector<ModelChange*> changeTo(string itop, string ibottom, string istate, string idirection, float idelay);  
		  
		vector<ModelChange*> changeTopTo(string itop, string state, string idirection, float idelay);  
		vector<ModelChange*> changeBottomTo(string ibottom, string state, string idirection, float idelay);  
		  
		vector<ModelChange*> changeStateTo(string istate, float idelay);  
		  
		void doChange(float idelay);  
		  
		void startModel();  
		void startModel(string imovie);  
		  
		void pauseModel();  
		void stopModel();  
				  
		string getMovie();  
		float  getMovieDuration();  
				  
		string getRelativeModelPosition(string imodel);  
		  
		void   setState(string istate);  
		string getState();  
		  
		void   setModelToLeft(string imodel);  
		string getModelToLeft();  
		  
		void   setModelToRight(string imodel);  
		string getModelToRight();  
		  
		string id;  
		  
		int x;  
		int y;  
		  
		string top;   
		string bottom;   
		string state;   
		string direction;   
		  
		string lastState;  
			  
		string modelToLeft;  
		string modelToRight;  
		  
		bool isDelaying;  
		bool isChanging;  
		  
		int  changeTime;  
		int  changeDelay;  
		  
		int lastActiveTime;  
		int maxInactiveTime;  
		  
		string movie;  
		  
		ofVideoPlayer movie1;  
		ofVideoPlayer movie2;   
		  
		bool isFading;  
		  
		ModelConstants *modelConstants;  
		Movies *movies;  
};  
  

thanks!

I just compiled the classes - seems like a circular include problem where ModelChange.h is including Model.h but Model.h is also including ModelChange.h.

Try removing:

#include “ModelChange.h”

from the top of Model.h

You will need to then forward declare the ModelChange type as the compiler won’t recognize it for these functions:

  
      vector<ModelChange*> changeTo(string itop, string ibottom, string istate, string idirection, float idelay);   
         
      vector<ModelChange*> changeTopTo(string itop, string state, string idirection, float idelay);   
      vector<ModelChange*> changeBottomTo(string ibottom, string state, string idirection, float idelay);   
         
      vector<ModelChange*> changeStateTo(string istate, float idelay);  

So this worked for me ( commented out Movies.h as I didn’t have it )

  
#pragma once   
  
#include "ofMain.h"   
  
//#include "ModelChange.h"  
//#include "Movies.h"   
  
class ModelChange;  //Forward declaration :)  
  
class Model {   
   public:   
      Model(string iid, int ix, int iy, string itop, string ibottom, string istate, string idirection, string imodelToLeft, string imodelToRight);   
      Model(const Model&);   
      Model();   
         
      void setup(string iid, int ix, int iy, string itop, string ibottom, string istate, string idirection);   
      void draw();   
      void update();   
         
      vector<ModelChange*> changeTo(string itop, string ibottom, string istate, string idirection, float idelay);   
         
      vector<ModelChange*> changeTopTo(string itop, string state, string idirection, float idelay);   
      vector<ModelChange*> changeBottomTo(string ibottom, string state, string idirection, float idelay);   
         
      vector<ModelChange*> changeStateTo(string istate, float idelay);  
         
.......  

  
#pragma once   
  
#include "ofMain.h"   
  
#include "Model.h"   
  
class ModelChange {   
   public:   
      ModelChange(Model imodel, string itop, string ibottom, string istate, string idirection, float idelay);   
      ModelChange(const ModelChange&);   
      ModelChange();   
  
.................  
  

For more on forward declarations - check here:
http://www.learncpp.com/cpp-tutorial/17-…-larations/

Theo

thanks so much for the link. that was a good article ,but i made the changes and my program is not compiling. im certain it is something simple and its possible i misunderstood something about forward declarations when using classes. do you declare the class its constructor arguments? in the add example the arguments are in the declaration. although i have a override constructor for each class which doesnt require arguments so that shouldnt be true.

hey no problem.

could you post a full zip with all files and also the errors you are getting.
that’ll be the quickest way to solve the bug :slight_smile:

theo

Hey - so I have been trying to get your project to compile and there are a ton of errors with the structures you are passing around (in constructors etc).

Did you write all this code in one go?
I would suggest trying to minimize the amount of objects you are passing around to each other, or build and test things one at a time. You have a lot of files that inter-rely on each other so it is quite a nightmare to debug :smiley:

If you need for objects to be copied over when passed in an argument you should define an = operator (see either ofxVectorMath or ofxOpenCV for examples how to do this).

Anyway to get rid of the errors you are currently getting.

ModelController.cpp

  
  
#include "ModelController.h"  
#include "ModelChangeQueue.h"  
  
ModelController::ModelController(vector<Model*> imodels) {   

ModelChange.cpp

  
   
   
  
#include "ModelChange.h"  
#include "ModelChangeQueue.h"  

ModelChange.h

  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
#include "Model.h"  
  
  
class ModelChange {  

ModelChangeQueue.h

  
#pragma once  
  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
#include "ModelChange.h"  
  
class ModelChange;  
  
class ModelChangeQueue {  
	public:  

Model.h

  
#pragma once  
  
#include "ofMain.h"  
  
#include "ModelConstants.h"  
//#include "ModelChange.h"  
  
class ModelChange;   
  
#include "Movies.h"  
  
class Model {  
	public:  

Model.cpp

  
/*  
  
#include "Model.h"  
#include "ModelChange.h"  
  
Model::Model(string iid, int ix, int iy, string itop, string ibottom, string istate, string idirection) {    

thanks so much for the suggestions! i am making changes.

Did u got the answer to It…I am also in a similar situation not knowing how to solve the error