I try to compile a simple class, but I always get the same error:
≥ clang++ LIF_network.cpp -std=c++11
LIF_network.cpp:3:1: error: expected unqualified-id
public LIF_network::LIF_network(){
^
1 error generated.
.hpp:
#ifndef LIF_NETWORK_HPP
#define LIF_NETWORK_HPP
#include <vector>
#include <cstdlib>
#include "LIF_neuron.hpp"
#include "currentTimer.hpp"
#define MAX_TIME 15
class LIF_network{
public:
LIF_network();
};
#endif //LIF_NETWORK_HPP
.cpp:
#include "LIF_network.hpp"
public LIF_network::LIF_network(){
mNumNeurons = 0;
mNeurons = std::vector<std::vector<LIF_neuron>>();
mOutput = std::vector<double>();
mCurrentTimer = CurrentTimer(MAX_TIME, mNumNeurons);
}
The error message does not really help me. Can you spot my mistake? Thanks a lot!
The access specifier (public: private: and protected:) only works within a class definition and not outside of it. It looks like you are trying to port Java code.
Related
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.
I'm trying to create a class network that you can create a network with parameters like the network ip.. and I want to pass also some nodes like the number of notebook, so on the network constructor I can create an array of notebook type, but it show me the following error , I don't know why,
please be patient I'm a beginner :C
I'll paste the essential code so if you need more for understand the issue I'll write to you, thanks.
class Network:
#pragma once
#include <iostream>
#include "Node.h"
#include "IpAdress.h"
using namespace std;
class Network{
protected:
NoteBook _notebook[100];
}
class Notebook:
#pragma once
#include <iostream>
#include "Node.h"
#include "IpAdress.h"
using namespace std;
class NoteBook : public Node {
public:
NoteBook() : Node() {
_networkAdress = IpAdress();
_hostAdress = IpAdress();
_powerState = false;
}
}
error C3646 :'_notebook': unknown override specifier
it also show me strange errors to to the line:" NoteBook _notebook[100];":
syntax error: ','missing before '['
syntax error: ','missing before '['
syntax error: ')' missing before ';'
unexpected token before ';'
I'm working on SFML here and I want to create my own RenderWindow class with Legacy. But the g++ prints this error: expected class-name before ‘{’ token at line 7 in .hpp
I all ready ask Google about it but I didn't find what I was expecting at so I hope you will be able to help me to find this out :)
my_render_window.hpp
#ifndef MY_RENDER_WINDOW_HPP_
# define MY_RENDER_WINDOW_HPP_
# include <SFML/Window.hpp>
class MyRenderWindow : public sf::RenderWindow
{
public:
MyRenderWindow();
protected:
};
#endif /* !MY_RENDER_WINDOW_HPP_ */
my_render_window.cpp
#include "my_render_window.hpp"
MyRenderWindow::MyRenderWindow(): sf::RenderWindow()
{
}
I compile correctly without these files and taking base sf::RenderWindow class to run with.
Okay, I dont know why but with this include #include <SFML/Graphics.hpp> just after the #include <SFML/Window.hpp> it works !
So weird... :(
#include <SFML/Graphics.hpp> may includes a file that I need to.
With my luck it's probably something very obvious that's slipped past me, but I've been struggling with C2143 for quite a while and I'm stumped.
game.h(21): error C2143: syntax error : missing ';' before '*'
game.h(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Game.h
#ifndef GAME_H_
#define GAME_H_
#include <irrlicht.h>
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::io;
using namespace irr::gui;
#include <iostream>
#include "CInput.h"
#include "CAssets.h"
using namespace rtsirr;
IrrlichtDevice *device = 0;
IVideoDriver *driver = 0;
ISceneManager *manager = 0;
CAssets *assets = 0; // Line 21, error here
#endif
CAssets.h
#ifndef ASSETS_H_
#define ASSETS_H_
#include "Game.h"
namespace rtsirr {
class CAssets
{
public:
CAssets();
virtual ~CAssets();
ITexture* getTexture(stringw name);
IMesh* getMesh(stringw name);
IAnimatedMesh* getAnimatedMesh(stringw name);
void load();
private:
map<stringw, ITexture *> *textures;
map<stringw, IMesh *> *meshes;
map<stringw, IAnimatedMesh *> *animatedMeshes;
};
}
#endif
It seems that CAssets isn't being recognized as a valid type, but I can't figure out why. What's causing the issue?
Thanks.
You have a cyclic dependency in your includes. Game.h includes CAssets.h which in turn includes Game.h before even getting to define CAssets. The result from the preprocessor would be different, depending on the order of includes.
From your sample code, it seems that Game.h doesn't really need to know much about CAssets other than that is a type. You could replace the inclusion of CAssets.h with a forward declaration:
class CAssets;
You can even provide a CAssets_fwd.h that does only that. Otherwise, you will need to break the cyclic dependency between those two headers.
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