Expected Class-name before { token - c++

I am trying to figure out whey I get an error: expected class-name before { token
Here is the relative source to the error:
#pragma once
#ifndef H_FXACTION
#define H_FXACTION
#include "CP_M_RefCounted.h"
#include "FxTypes.h"
#include "string"
#include "FxString.h"
#include "FxPixels.h"
#include "CP_Rect.h"
#include "FxStreamable.h"
#include "FxPoint.h"
#include "FxPtr.h"
#include "FxImage.h"
#include "FxSleekStreaming.h"
typedef FxID FxActionType;
typedef FxUInt32 FxActionID;
FxActionID FrMakeUniqueActionID(void);
class FxActionData;
class FxActionData : public CP_M_RefCounted
{
public:
FxActionData();
FxActionData(FxBool final) :mFinal(final) { }
virtual ~FxActionData();
I get the error at this line: class FxActionData : public CP_M_RefCounted
What I dont get is why the line: class FxActionData; is there when you are creating the class directly under it. Isn't this a forward declaration?
What things could be going on here?

class FxActionData; is a *forward declaration. It doesn't hurt anything but allows for not dragging in a full header file for, say, just a pointer to a class. It's useless in your case here.
The CP_M_RefCounted is probably a template (or might be declared in a namespace). Look into what's in CP_M_RefCounted.h

Related

c++ error: expected class-name before '{' token

screenshot of Pose.hpp
I am trying to catkin_make a simple package and I am getting the error
.../Pose.hpp:17:1: expected class-name before token...
.../Odometry.cpp:12:3: expected class-name before token...
The responsible Pose header file is sampled here as:
#ifndef POSE_HPP
#define POSE_HPP
#include <string>
#include <vector>
#include <ostream>
#include "ros/serialization.h"
#include "ros/builtin_message_traits.h"
#include "ros/message_operations.h"
#include "ros/message.h"
#include "ros/time.h"
namespace turtle
{//line 17
template <class ContainerAllocator>
struct Pose_ : public ros::Message
{
typedef Pose_<ContainerAllocator> Type;
}; // struct Pose
...
} // namespace turtle
while on the referred header file is referenced in odometry.cpp shown as
#include <geometry_msgs/TwistWithCovarianceStamped.h>
#include <tf/transform_datatypes.h>
#include <robot_localization_demo/odometry.hpp>
namespace robot_localization_demo {
TurtleOdometry::TurtleOdometry(ros::NodeHandle node_handle, double frequency):
node_handle_{node_handle},
turtle_pose_subscriber_{node_handle_.subscribe("turtle1/pose", 16, &TurtleOdometry::turtlePoseCallback, this)},
turtle_twist_publisher_{node_handle_.advertise<geometry_msgs::TwistWithCovarianceStamped>("turtle1/sensors/twist", 16)},
frequency_{frequency},
{//line 12
;
}
and odometry includes Pose as well.
what am I missing here?
The official documentation for ros::Message says:
This base-class is deprecated in favor of a template-based serialization and traits system.
In the official source code it looks like it's still defined, but in a contrib version I found, the whole class definition is removed by #if 0:
namespace ros {
#if 0
class Message {
//
};
#endif
}
So, you most probably need to find a different base class.

compile multiple files c++, doesnt name a type

I have a problem compiling multiple files with codeblocks. My problem is that the compiler doesnt recognize the class types that i created. I get the error doesnt name a type. I have add at all header files the #ifndef, #deffine. My files are:
forum.h
#include <list>
#include "thread.h"
class Forum
{
private:
std::list<Forum*> forums;
std::list<Thread*> themata;
}
thread.h
#include <list>
#include "forum.h"
#include "post.h"
class Thread
{
private:
Forum* forum; //gia tin allagi thesis otan ginei stick
int id;
std::list <Post*> lista;
}
post.h
#include "system.h"
class Post
{
private:
System* system;
}
What can i do for that ?
You have a circular header dependency. Use forward declarations to break it. For example, in forum.h, forward declare the Thread class instead of including its header like this:
#include <list>
class Thread;
class Forum
{
private:
std::list<Forum*> forums;
std::list<Thread*> themata;
};
Include the header in forum.cpp.

inheritance from within a namespace error

I have the following piece of code:
#include <pcl/recognition/ransac_based/model_library.h>
#include <pcl/common/common.h>
#include <pcl/features/shot.h>
namespace pcl
{
class LSDPointPairModelLibrary : public ModelLibrary
{ ... }
}
I am getting the error:
expected class-name before '{' token
I also tried qualifying the superclass like so: pcl::recognition::ModelLibrary but I get the error pcl::recognition has not been declared
Atn least you must provide the sub-namespace recognition, but pcl::recognition should also work. Did you not forget the semicolon at the end of the class definition? You could try ::pcl::recognition::ModelLibrary to make sure you start from the top level namespace.

Expected class-name before ‘{’ token

I'm receiving the error:
In file included from proprietario.h:5,
from veiculo.h:4:
motocicleta.h:8: error: expected class-name before ‘{’ token
Motocicleta.h:
#ifndef __MOTOCICLETA__
#define __MOTOCICLETA__
#include <iostream>
#include "veiculo.h"
#include "proprietario.h"
using namespace std;
class Proprietario;
class Motocicleta:public Veiculo{
public:
Motocicleta(int nPassageiros, string modelo, string placa, int aFabricacao, Proprietario* pai, int nRodas, int aro);
~Motocicleta();
Motocicleta (const Motocicleta& source);
Motocicleta& operator= (const Motocicleta& source);
string toString();
};
#endif
Proprietario.h
#ifndef __PROPRIETARIO__
#define __PROPRIETARIO__
#include <iostream>
#include "motocicleta.h"
#include "caminhao.h"
#include "carreta.h"
#include "carro.h"
using namespace std;
class Carro;
class Carreta;
class Caminhao;
class Motocicleta;
class Proprietario{
protected:
string nome;
string cpf;
Motocicleta* mMoto;
Caminhao* mCaminhao;
Carreta* mCarreta;
Carro* mCarro;
};
Veiculo.h:
#ifndef __VEICULO__
#define __VEICULO__
#include <iostream>
#include "proprietario.h"
#include "roda.h"
#include "motor.h"
using namespace std;
class Motor;
class Proprietario;
class Veiculo{
protected:
int nPassageiros;
string modelo;
string placa;
int aFabricacao;
Proprietario* pai;
Roda* rodas;
Motor* mMotor;
int nRodas;
};
I removed the methods, because if i added those the question will be to long, sorry, the code is in PT-BR.
I saw that the problem is usually is forward declaration.
But i cannot find out the problem, i looked in so many forums but i cannot find out the problem..
Someone can help me?
Need any other part of the code?
The real problem here is the liberal use of #include preprocessor directives. In general, you should only include a header file at the lowest scope at which it is needed and forward-declare everything you can. You simply don't (shouldn't) generally need full class declarations for header files. Header files do not generally need to know about implementation details. You definitely shouldn't been forward-declaring and including the header.
As the code stands in the question at the time of writing this answer, you have a circular dependency on veiculo.h (and also on proprietario.h). As veiculo.h really is needed for the header of its subclass Motocicleta, you should remove the #include directives for the classes you have already forward-declared in each of the headers. You can then include the headers in the source files as needed.

Invalid use of undefined type 'struct PelephonePH'

i have received in .cpp errors of invalid use of undefined struct PelephonePN, CellcomPN and so on
and also error in .h errors of forward declaration of PelephonePN,...
#ifndef PHONE_H_INCLUDED
#define PHONE_H_INCLUDED
#include <iostream>
#include <ctime>
#include <string>
#include "phone.h"
using namespace std;
class PhoneNumber;
class PelephonePN;
class CellcomPN;
class OrangePN;
class HotPN;
class BezeqPN;
class PhoneManager
{
private:
PelephonePN* mpPelephone;
CellcomPN* mpCellcom;
OrangePN* mpOrange;
HotPN* mpHot;
BezeqPN* mpBezeq;
public:
PhoneManager();
~PhoneManager();
void split_check_data(string str);
};
#endif
and .cpp
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include "phone_manager.h"
#include "phone.h"
using namespace std;
PhoneManager::PhoneManager()
{
srand(time(0));
mpPelephone = new PelephonePN();
mpCellcom = new CellcomPN();
mpOrange = new OrangePN();
mpHot = new HotPN();
mpBezeq = new BezeqPN();
mpPelephone->add(mpCellcom);
mpPelephone->add(mpOrange);
mpPelephone->add(mpHot);
mpPelephone->add(mpBezeq);
mpBezeq->setNext(mpPelephone);
}
To instantiate an object, forward declaration is just insufficient. Include the corresponding headers in the source file. In the body of the constructor, you are instantiating mpPelephone, ..... So, make sure that corresponding class headers can be seen in the translation unit.
In your .cpp source file you need to #include the headers that define class PelephonePN and its associates.
It is fine to forward-declare these classes in the header if you are only using them as pointers or references, but one you start using them in your implementation, you'll need to provide the compiler with the definition.
You can't use a forward declaration of a class to access its members (which includes the constructor, default or otherwise) or its size and without those two things, you can't instantiate an instance of that class.
You require its FULL implementation to do that, so in your .cpp file you need to include the header with the whole class PelephonePN {/* class body */}; section.
in the first file you have lines:
#ifndef PHONE_H_INCLUDED
#define PHONE_H_INCLUDED
I suppose you have same lines in phone.h, please check...
Are your PelephonePN and co. in a particular namespace? If so, predeclarations must all be in the same namespace. Since you added a using namespace std (sigh), my guess is that phone.h is defining your classes inside the namespace std (I hope it doesn't, but that's another thing).
If so, your predeclarations must be:
namespace std {
class PelephonePN;
}
Btw, what is a pelephone??? O.O