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.
Related
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 ';'
So I am working on a program that is due tomorrow and for some reason I keep getting this 2 errors, if I click on the first one it takes me to the iostream file and right before the _STD_BEGIN it wants me to put ";" but if I do that it messes up the file in the library so I am pretty sure I do not have to do that, the second error is in my main.cpp and it points to using namespace std; and it wants me to put a ";" before it =, if I do so the error disappears and it keeps pointing at the iostream error....
I have no idea what to do and my deadline is tomorrow.
This is my main.cpp include section with the modification to using namespace std
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include "Package.h"
;using namespace std;
Look for a class or struct definition in Package.h that's missing its semicolon. ie.
class act
{
// yadda
} // no semicolon here
Then add the missing semicolon.
When you get a "missing ;type error on a line that follows closeley behind a bunch of#includestatements, the likely culprit is a missing;` in one of the header files. To find out which, start at the last include file, Package.h. You'll surely find a missing semicolon there. It's probably missing after a class declaration, as if you had written:
class Foo
{
}
instead of
class Foo
{
};
I have several files, listed just below, wherein I define some namespaces and classes. Then in one of the files I am trying to incorporate the classes from the others. The issue is that the compiler seems to not be able to find my namespaces.
charon.cpp
chin.cpp
chout.cpp
main.cpp
My namespaces are charon, charon_in, and charon_out. The main problems come up on a particular file, charon.cpp, so here is that file and chin.cpp too.
The errors:
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/sys/charon.o.d -o build/Debug/GNU-Linux-x86/sys/charon.o sys/charon.cpp
sys/charon.cpp:6:17: error: ‘charon_in’ is not a namespace-name
sys/charon.cpp:6:26: error: expected namespace-name before ‘;’ token
sys/charon.cpp:7:17: error: ‘charon_out’ is not a namespace-name
sys/charon.cpp:7:27: error: expected namespace-name before ‘;’ token
sys/charon.cpp:15:5: error: ‘chout_’ does not name a type
sys/charon.cpp:16:5: error: ‘chin_’ does not name a type
sys/charon.cpp:31:39: error: ‘chin_’ has not been declared
sys/charon.cpp:31:55: error: ‘engine_input’ was not declared in this scope
sys/charon.cpp:32:40: error: ‘chout_’ has not been declared
sys/charon.cpp:32:57: error: ‘engine_output’ was not declared in this scope
charon.cpp
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
using namespace std;
using namespace charon_in;
using namespace charon_out;
namespace charon
{
class charon_
{
private:
chout_ engine_output;
chin_ engine_input;
boost::thread input_thread;
boost::thread output_thread;
void start_threads();
void stop_threads();
public:
//Methods
};
chin.cpp
#include <iostream>
#include <borland/conio.h>
#include <ncurses.h>
#include <boost/thread.hpp>
using namespace std;
using namespace charon;
using namespace charon_out;
namespace charon_in
{
class chin_
{
private:
bool pause;
charon_* engine;
inline iostream grab();
public:
//Methods
};
I triple checked everything. So I am pretty confident the syntax is correct, but obviously I'm missing some key concept otherwise the compiler wouldn't complain.
(I know putting classes in the cpp files isn't a standard thing to do, but I know it is possible to do it so that's why I chose to try.)
I can't see what mistakes I've made. Any help would be appreciated.
You need to include the header file that declares the namespace (or declare it again) before the using directive:
// using namespace test; // Error test is not known to be a namespace
namespace test {}
using namespace test; // Fine -- test is known
As Wayne correctly points out, you probably want to restructure your code differently, including header files that will contain the declarations and can be included in different translation units.
You have the class declarations and the definitons in the .cpp files. You need to move the class declarations to a .h file and include it in the appropriate files that are using the class.
For example, move the following to chin.h and include chin.h in charon.cpp.
namespace charon_in
{
class chin_
{
private:
bool pause;
iostream key_sequence;
deque<char> key_queue;
charon_* engine;
inline iostream grab();
public:
chin_(const charon_& handle);
chin_(const chin_& orig);
~chin_();
void refresh();
bool stop_check();
};
}
Be wary of cyclic dependencies for they can also cause the compiler to not find the namespace you require.
//In rightWing.h
include "leftWing.h"
// code
//In leftWing.h
include "rightWing.h"
// code
This is weird. I created a vector just fine in one class but can't create it in another class. He's a representation of what I have:
main.h
#include <Windows.h>
#include <ShellAPI.h>
#include <vector>
#include <string>
#include <iostream>
#include "taco.h"
class MyClass
{
public:
int someint;
vector<int> myOrder;
};
taco.h
#include <vector>
class OtherClass
{
public:
vector<int> otherOrder;
};
And I get compile errors regarding the vector declaration in taco.h:
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
What am I missing here? I can uncomment out that second vector declaration and it compiles fine.
Try:
std::vector<int> otherOrder;
vector is part of the std namespace. This means that whenever you use a vector in a header file, you should include the std:: prefix.
The reason that you can sometimes get away with forgetting it is that some included files may have using namespace std; in them, allowing you to leave off the prefix. However, you should avoid the using keyword in header files, for it will pollute the namespace of any files that include it.
For a more detailed explanation of the dangers of using namespace ..., see this thread.
Try std::vector<int>. You're supposed to use the namespace --- I'm assuming you have
using namespace std;
in the main.h someplace. There's a lot of talk on SO as to why using using is bad practice ; I'd recommend that you check it out.
All C++ standard library objects live in the std namespace. Try
class MyClass
{
public:
int someint;
std::vector<int> myOrder;
// ^^^^^
};
std::vector<int> ?
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