Hi I am writing a C++ program using OpenCV. I make sure to include the necessary files:
#include "opencv2/core/core.hpp"
#include "opencv2/ml/ml.hpp"
Everything using opencv works fine and dandy. But when I refer to Node in the following line:
std::vector<Node> nodeList = forest->getNodes();
I get the following error:
error: use of undeclared identifier 'Node'
I don't understand why, because it recognizes all the other opencv classes. There is probably a simple explanation for this but I don't see it right now. Any help would be greatly appreciated!
Try the full name of the node class cv::ml::DTrees::Node. and if you want to define a vector with a certain size do this:
std::vector<Node> nodeList(forest->getNodes().size());
Related
there is something that has been bugging me for a while.
I cannot create a destructor using Xcode (with other IDEs like VS2021 that is no issue).
I get the error:
1. Constructor cannot be redeclared
2. Missing return type for function '˜Pointer'; did you mean the constructor name 'Pointer'?
If I try to declare outside of the class and uncomment the lines in *.cpp and *.hpp the errors get even crazier.
My Pointers.hpp is the following:
#ifndef Pointers_hpp
#define Pointers_hpp
#include <iostream>
class Pointer{
public:
Pointer(void);
˜Pointer(void){};
//˜Pointer(void);
};
#endif /* Pointers_hpp */
and my Pointers.cpp is this one:
#include "Pointers.hpp"
Pointer::Pointer(void){};
//Pointer::˜Pointer(void){};
After several research in the internet, I could not find a solution to that, could any one give me a light on this?
Many thanks in advance,
Raphael
Solved thanks to user4581301:
For those having the same problem I did.
The issue here was the similarity between ˜ and ~
The correct one should be ~
If you are using MacBook Pro the short-key is Option-N.
I am trying to use a function from another class but my dependencies seem to be stopping me.
main.cpp
#include "gesture.hpp"
#include "statemachine.hpp"
Gesture g;
StateMachine sm(g);
gesture.hpp
#include "hand.hpp"
statemachine.hpp
#include "gesture.hpp"
StateMachine(Gesture&);
Gesture *g;
What I am trying to accomplish:
I am trying to use a function from the StateMachine sm that I have declared. This function would be called inside a function in gesture.cpp and I would be giving my Gesture g class a pointer to StateMachine sm. (I would do this after I declare sm in main) I am able to #include "statemachine.hpp" in my gesture.cpp file but I want to move it to gesture.hpp so I can have it as a pointer that is stored as a variable in that class.
So when I do
gesture.hpp
#include "hand.hpp"
#include "statemachine.hpp"
I get the error 'Gesture' does not name a type and expected ')' before '&' token StateMachine(Gesture&);
Can anyone figure out what is going on? I can't move my function to gesture.cpp because it uses an array that is stored in my statemachine.hpp
You didn't provide the details so i will post my guess here.
When the precompiler analyze "gesture.hpp", it will unroll it to something like this:
codes in hand.hpp
StateMachine(Gesture&);
Gesture *g;
the file "gesture.hpp" is not unrolled in statemachine.hpp because i think you had provided some protections against circular dependency. so the compiler don't know what Gesture is.
To solve the compiling error, you can put a forward declaration of Gesture to statemachine.hpp, like this:
class Gesture;
StateMachine(Gesture&);
Gesture *g;
I'm trying to run this repo for curiosity: https://github.com/jzeimen/PuzzleSolver/tree/master/PuzzleSolver
Eclipse throws the title error "'MSize' is not a member of cv::Mat' whenever I try to run the following line of code from PuzzleDisjointSet.cpp:
cv::Mat::MSize size_of_a = sets[rep_a].locations.size;
Where locations is defined like so:
struct forest{
cv::Mat_<int> locations;
cv::Mat_<int> rotations;
int representative;
int id;
};
and sets is a vector version of the forest structure. I'm mainly confused as to why this is occurring, when documentation clearly refutes this.
I believe the header files I am including are the correct ones (PuzzleDisjointSet.h includes the above forest structure definition as well as the sets definition.
#include "PuzzleDisjointSet.h"
#include <algorithm>
#include <opencv2/core.hpp>
#include <opencv/cv.h>
#include <opencv2/core/mat.hpp>
the struct was removed in this commit
https://github.com/Itseez/opencv/commit/d8c8339bec83b77978d2a0e1a62b764fb9d9c599#diff-bc1d784738cd852f5b1e95ce10a56d06
maybe you can checkout a version before that and use it, or i suspect it may have been moved to a different class, you can try looking for that
OpenCV version: 4.3.0
cv::MatSize size_of_a = sets[rep_a].locations.size;
I have this header file:
//region.hpp
#ifndef REGION_HPP
#define REGION_HPP
...
#include "spacepoint.hpp"
class Image;
//class SpacePoint;
class Region
{
Rectangle<SpacePoint> boundaries;
...
it gives this error
error: ‘SpacePoint’ was not declared in this scope
when I uncomment class SpacePoint i get this:
In instantiation of ‘class Rectangle<SpacePoint>’:
region.hpp:15:27: required from here
rectangle.hpp:19:7: error: ‘Rectangle<T>::start’ has incomplete type
I tried to reproduce the problem with a smaller test program but I can't.
I don't know how to go about solving this.
thanks to #Matteo's guidance I fixed the issue.
With this answer I configured doxygen to show the header files dependency.
It was easier to find the loops this way.
Where an include wasn't necessary I removed the include and added a declaration.
In the case of spacepoint.hpp I effectively turned #include <image.hpp> to class Image;
Before:
After:
(the graph is smaller as spacepoint.hpp doesn't depend on image.hpp anymore)
This is a weird question in that I'm not sure where to start looking.
First of all, I haven't done any C++ programming for the last 10 years so it could be me thats forgotten a few things. Secondly, the IDE I'm using is Eclipse based (which I've never used) and customized for Samsung bada based mobile development (it kicks off an emulator for debugging purposes)
I'm posting my code samples as images because the StackOverflow WYSIWYG editor seems to have a problem parsing C++.
[EDIT] Due to complaints I've edited my question to remove the images. Hope that helps :)
I have the following header file...
#include <FApp.h>
#include <FBase.h>
#include <FGraphics.h>
#include <FSystem.h>
#include <FMedia.h>
using namespace Osp::Media;
using namespace Osp::Graphics;
class NineAcross :
public Osp::App::Application,
public Osp::System::IScreenEventListener
{
public:
static Osp::App::Application* CreateInstance(void);
public:
NineAcross();
~NineAcross();
public:
bool OnAppInitializing(Osp::App::AppRegistry& appRegistry);
private:
Image *_problematicDecoder;
};
...and the following cpp file...
#include "NineAcross.h"
using namespace Osp::App;
using namespace Osp::Base;
using namespace Osp::System;
using namespace Osp::Graphics;
using namespace Osp::Media;
NineAcross::NineAcross()
{
}
NineAcross::~NineAcross()
{
}
Application* NineAcross::CreateInstance(void)
{
// Create the instance through the constructor.
return new NineAcross();
}
bool NineAcross::OnAppInitializing(AppRegistry& appRegistry)
{
Image *workingDecoder;
workingDecoder->Construct();
_problematicDecoder->Construct();
return true;
}
Now, in my cpp file, if I comment out the line that reads _problematicDecoder->Construct();...I'm able to set a breakpoint and happily step over the call to Constuct() on workingDecoder. However, as soon as I uncomment the line that reads _problematicDecoder->Construct();... I end up with the IDE telling me...
"No source available for "Osp::Media::Image::Construct()"
In other words, why can I NOT debug this code when I reference Image *image from a header file?
Any ideas?
Thanks :-)
This usually means you're stepping through some code which you do not posses its source.
I assume here that Osp::Media::Image is a class supplied by Samsung or similar for which you do not have the cpp file. So this means the debugger can't show you the current code line while you're at a function of Osp::Media::Image.
Alternatively, there's a good chance you do have all of the source code for this class, but Eclipse doesn't know where it is. In this case you can add the correct directories under the Debug Configurations window.
Ok, problem solved.
The idea is to first new up an instance of Image like so...
_decoder = new Osp::Media::Image();
And then do _decoder->Construct().
Funny enough, this seems blatantly obvious to me now coming from the C# world, though why the code I posted for workingDecoder works is still somewhat mysterious to me. The fact the sample projects pre-loaded with the bada IDE don't seem to make a call to new() leads me to believe that perhaps those samples are outdated our out of synch.
Either that or I really AM wildly out of the C++ loop.
Anyway thanks so much for the effort guys.
Appreciated :)