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.
Related
I'm working in a multiplatform project using OpenGL and get to the point where I needed to query the current context.
In windows I used wglGetCurrentContext() including windows.h that worked fine.
On the other hand, when tried to compile in linux I'm using glXGetCurrentContext() and including glx.h which internally includes Xlib.h and X.h
It happens that in my source code I have a class called Status but there is a macro called the same in Xlib, i.e. #define Status int, Aha ! big problem now since I use my class everywhere.
What would be the best way to overcome this problem? The ideas I have in mind right now are
Rename my class to something else ... but why?
Use #pragma push_macro("Status") followed by a #undef Status
Find a more robust and portable way to query OpenGL's context
If you have any other recommendation let me know, I appreaciate it very much.
at a bare minimum, you may isolate glXGetCurrentContext() into its own translation unit:
myGlXGetCurrentContext.hpp
GLUint myGlXGetCurrentContext();
myGlXGetCurrentContext.cpp
#include<glx.h>
GLUint myGlXGetCurrentContext(){ return glXGetCurrentContext(); }
whatever.hpp
#include<myGlXGetCurrentContext.hpp>
...
Try to put Your classes in namespace.
http://en.cppreference.com/w/cpp/language/namespace
https://msdn.microsoft.com/en-us/library/5cb46ksf.aspx
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 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)
I know this has been asked a thousands times, but I'm stumped. I've been looking all over for that last 3 days without a result. I keep getting this error and I can't figure out why.
I've added only the code that I have input / that matters. If I comment out my code the program compiles without a problem. What am I doing wrong???
CMakeFiles/brewtarget.dir/MainWindow.cpp.o: In function MainWindow::MainWindow(QWidget*)':
MainWindow.cpp:(.text+0xb145): undefined reference to yeastCellCounter::yeastCellCounter()'
CODE
mainwindow.cpp
#include "yeastcellcounter.h"
// a whole lot of stuff between these...
yeastCountDialog = new yeastCellCounter();
mainwindow.h
class yeastCellCounter;
// A whole log of stuff between these...
yeastCellCounter *yeastCountDialog;
yeascellcounter.cpp
#include "yeastcellcounter.h"
yeastCellCounter::yeastCellCounter(){}
yeastcellcounter.h
#ifndef YEASTCELLCOUNTER_H
#define YEASTCELLCOUNTER_H
class yeastCellCounter
{
public:
yeastCellCounter();
};
#endif // YEASTCELLCOUNTER_H
This are the INCLUDE_DIRECTORIES directive in cmakelist.txt
SET(ROOTDIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(SRCDIR "${ROOTDIR}/src")
SET(UIDIR "${ROOTDIR}/ui")
SET(DATADIR "${ROOTDIR}/data")
SET(TRANSLATIONSDIR "${ROOTDIR}/translations")
SET(WINDIR "${ROOTDIR}/win")
INCLUDE_DIRECTORIES(${SRCDIR})
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src") # In case of out-of-source build.
INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/QtDesignerPlugins")
Whenever you see a error of the type undefined reference to ... it is a linker error. This means that the compiler has completed it's work and all the object files have been compiled without errors. It's now time for the linker to put all the pieces together into a single file.
In your specific example, it says that it cannot find the definition of the function yeastCellCounter::yeastCellCounter(). From the code you have pasted, this function, albeit empty, is clearly defined in the file yeascellcounter.cpp.
It looks like your cmakelists.txt file is incomplete. You haven't specified which source files need to be linked together to create your final executable. You need to use the add_executable statement for this.
Here's a simple example
The problem is:
yeastCountDialog = new yeastCellCounter();
It should be:
yeastCountDialog = new yeastCellCounter;
(Notice the lack of parentheses). The default constructor is always called without parentheses. And also, you need to add "yeastcellcounter.cpp" to the list of cmake sources.
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 :)