I added a file in source control which had an enum definition as:
enum { OK = 0, ERROR };
But on compilation it was throwing errors like "expected identifier before numeric constant."
Did my research on that and the culprit was supposed to be 'OK' which was defined somewhere else in the code. So, i changed OK with say, OK_1, and the issue was, indeed, resolved.
However, I have not been able to find where in my code base was this 'OK' defined before.
I ran a grep from top level and couldn't find it. I am pretty sure I have covered all the application related code, but OK wasn't there.
I think it's unlikely that it was a part of some shared library as compilation process didn't even reach linking phase. It could have come from one of the header files maybe.
Is there a way/linux tool that somehow can be tricked to find where this OK is coming from?
If you are using C++ 11 take a look at enum class:
http://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html
One big draw back of enum is that you cant have 2 enums with the same name.
With enum class this draw back is gone, you can write thing like this:
enum class Color {RED, GREEN, BLUE};
enum class Feelings {EXCITED, MOODY, BLUE};
And later on in the code:
Color color = Color::GREEN;
if ( Color::RED == color )
{
// the color is red
}
Code example is pasted from linked www page
Converting my comment to answer.
Looks like you need pre-processor output Can gcc output C code after preprocessing?
my English is not good,but you can try enum var{xxx,xxx},you can customize var.
Related
I want to delete all the object that is not used now.
I used Visual Studio 2019.
When I search Object Browser, It gets to me some strange struct or class that I modified of name.
For example, first I define a structure as
typedef struct stOutput
{
double dDirtyPrice_CumInt;
double dDM;
//...
double dYield;
} stOutput
Later I changed this definition to
typedef struct stOutput_New
{
double dAI;
//...
long lObservStartDate;
} stOutput_New
However, the object browser shows to me just
stOutput.
There is no stOutput_New.
Also I put my cursor on 'stOutput_New' and push 'F12' then it locates my view some strange area.
There are even no 'stOutput_New'
Now, below picture is describing my real situation
This is 'Class View'
Actually I just use One stOutput, but there are so many stOutput that has same file path
Also below picture is my 'Object Browser'
As you can see the two stOutput have different member variables.
And I changed the name from stOutput to stOutput_new the latter.
But it seems my object browser didn't reflect it.
I tried
Project Unload and Reload it
Organize the code of Solution and Project
Re-Build Solution.
But everything doesn't work.
Please help me
In vs2019, I defined the structure exactly like yours according to your description, and then changed the structure according to your description. My object browser did not have the problem you described. If you are sure that your code does not repeat the definition of structure and other problems, I suggest you reinstall or repair VS.
enter image description here
This is my first question ever posted, so please let me know if there is anything that needs changes in my post :)
I am currently working on a dialog that is supposed to let the user change the background-color for some signal plotting. The "wxColourPickerCtrl" seems to do exactly what I need. Since there are multiple plots/pictures to be manipulated, the ColourPickerCtrls are initialized in a loop with the chosen background color as the default value:
for (const auto& [signalName, signalProperties] : properties)
{
wxColourPickerCtrl* selectBackgroundColor = new wxColourPickerCtrl(this, signalProperties.first, signalProperties.second.backgroundColor, wxDefaultPosition, wxDefaultSize);
}
"this" is an object of type SignalPropertiesDialog, which is directly inherited from wxDialog.
I have left out all the necessary sizer stuff, since it's not relevant for the problem (at least imo). "properties" is structured as follows:
std::map<std::string, std::pair<int, GraphPicture::Properties>> signalProperties_;
where GraphPicture::Properties contains the properties I want to manipulate:
struct Properties
{
wxColour backgroundColor{ *wxWHITE };
wxColour lineColor{ *wxBLACK };
int linewidth_px{ 1 };
bool isShown{ true };
};
The application successfully builds but immediately crashes on startup while generating those color picker objects.
wxIshiko has uploaded multiple tutorials and code snippets as examples for various wxWidgets controls, including the wxColourPickerCtrl. So I downloaded the sample code and tried to run it. Surprisingly, it worked.
While running through the code step by step I noticed the following difference:
The wxColourPickerCtrl is based on wxPickerBase. The wxPickerBase is created by calling the constructor of wxColourPickerCtrl (what I am actually doing in my code). During the construction of the wxPickerBase, the desired color is called by the name wxColourDataBase::FindName(const wxColour& color) const where the wxColourBase itself is instantiated. This is where the difference is:
When running the code snippet by wxIshiko, wxColourDataBase is instantiated correctly including the member m_map of type wxStringToColourHashMap* which is set to be NULL.
When running the code written by myself, wxColourDataBase is not correctly instantiated, and thus the member m_map is not set to be NULL, which leads to to the crash.
I have the feeling that there is nothing wrong with the way I set up the wxColourPickerCtrls. I somehow think there is a difference in the solution properties of the projects. I checked those but was not able to find any relevant differences.
I would really appreciate any hint or help since I am completely stuck on that problem.
Thank you very much in advance and have a good one,
Alex
EDIT:
I attached a screeny of the call stack.
Call stack
When does this code run exactly? If it is done after the library initialization (which would be the case, for example, for any code executed in your overridden wxApp::OnInit()), then wxTheColourDatabase really should be already initialized and what you observe should be impossible, i.e. if it happens it means that something is seriously wrong with your library build (e.g. it doesn't match the compiler options used when compiling your applications).
As always with such "impossible" bugs, starting with a known working code and doing bisection by copying parts of your code into the working version until it stops working will usually end up by finding a bug in your code.
I am trying to create a very simple MFC application when suddenly Visual Studio decides it no longer recognizes what a BOOL is.
I cannot figure out why this is happening. Does anyone know why this is going on and how to fix it?
It looks like you're missing a closing semi-colon at the end of your class.
class CApp : public CWinApp {
...
}; <---
This is the proper class syntax. I'm sure you know that and just happened to delete it and missed the simple error. I would say when you look at the error report it's best to solve the topmost one first. Doing so can eliminate other errors in the list especially in the case of a ;. Your image reflects that on the first line where it tells you about a missing ;.
Has anyone done trimesh refining in the VCG library? I would add that as a tag but I don't have high enough reputation yet. Every time I include any of the refine libraries I get the following errors:
../../../addons/ofxVCGLib/vcglib/vcg/complex/trimesh/refine.h:880:0
../../../addons/ofxVCGLib/vcglib/vcg/complex/trimesh/refine.h:880: error: expected
unqualified-id before numeric constant
which is on this line:
typename TRIMESH_TYPE::FacePointer FF0;
the definition that contains that (excuse the giant c/p) looks like this:
template<class TRIMESH_TYPE, class CenterPoint>
void TriSplit(typename TRIMESH_TYPE::FacePointer f,
typename TRIMESH_TYPE::FacePointer f1,typename TRIMESH_TYPE::FacePointer f2,
typename TRIMESH_TYPE::VertexPointer vB, CenterPoint Center)
{
my vertex, face, & mesh are declared like so:
class innerMeshFace:public Face<myTypes, face::FFAdj, face::Mark, face::VertexRef, face::BitFlags, face::Normal3f, face::InfoOcf> {
};
class myVertex:
public Vertex<myTypes, vertex::Coord3f, vertex::BitFlags, vertex::TexCoord2f, vertex::Normal3f, vertex::Mark, vertex::Color4b, vertex::VFAdj, vertex::InfoOcf>
{}
class myMesh:public tri::TriMesh< vector<myVertex>, vector<innerMeshFace> > { }
so I'm not sure if there's something in there that's I'm misunderstanding. I use the myMesh::FacePointer elsewhere in my code, I think there's something in the template pile that I'm missing. This all works fine (i.e. compiles and does what it's supposed to) until I try to include the refine.h. Any pointers from anyone w/VCG experience would be very much appreciated.
After talking to the creators, it turns out this is a problem in how GCC compiles that particular part of the library. I don't understand the details, but LLVM is fine with it, GCC is not. It works fine on Linux but as I was working with it in XCode I was having problems. It's something they're not going to be updating any time soon, so it looks like for the moment VCG mesh-refining isn't working on GCC 4.2.
I got an example of Refine working (finally!) under MingW GCC-3.4.5 http://pastebin.com/uYnCepEY
I have a header file with all the enums listed (#ifndef #define #endif construct has been used to avoid multiple inclusion of the file) that I use in multiple cpp files in my application.One of the enums in the files is
enum StatusSubsystem {ENABLED,INCORRECT_FRAME,INVALID_DATA,DISABLED};
There are functions in the application delcared as
ShowStatus(const StatusSubsystem&);
Earlier in the application when I made calls to the above function like
ShowStatus(INCORRECT_FRAME);
my application used to compile perfectly. But after some code was added The compilation halts giving the following error:
File.cpp:71: error: invalid conversion from `int' to `StatusSubsystem'
File.cpp:71: error: initializing argument 1 of `void Class::ShowStatus(const StatusSubsystem&)
I checked the code for any conflicting enums in the new code and it looked fine.
My Question is what is wrong with the function call that compiler shows as erroneous?
For your reference the function definition is:
void Class::ShowStatus(const StatusSubsystem& eStatus)
{
QPalette palette;
mStatus=eStatus;//store current Communication status of system
if(eStatus==DISABLED)
{
//select red color for label, if it is to be shown disabled
palette.setColor(QPalette::Window,QColor(Qt::red));
mLabel->setText("SYSTEM");
}
else if(eStatus==ENABLED)
{
//select green color for label,if it is to be shown enabled
palette.setColor(QPalette::Window,QColor(Qt::green));
mLabel->setText("SYSTEM");
}
else if(eStatus==INCORRECT_FRAME)
{
//select yellow color for label,to show that it is sending incorrect frames
palette.setColor(QPalette::Window,QColor(Qt::yellow));
mLabel->setText("SYSTEM(I)");
}
//Set the color on the Label
mLabel->setPalette(palette);
}
A strange side effect of this situation is it compiles when I cast all the calls to ShowStatus() as
ShowStatus((StatusSubsystem)INCORRECT_FRAME);
Though this removes any compilation error, but a strange thing happens. Though I make call to INCORRECT_FRAME above but in function definition it matches with ENABLED. How on earth is that possible? Its like while passing INCORRECT_FRAME by reference, it magically converts to ENABLED, which should be impossible. This is driving me nuts.
Can you find any flaw in what I am doing? or is it something else?
The application is made using C++,Qt-4.2.1 on RHEL4.
Thanks.
You should take the enum by value, rather than by const reference. It's small enough to fit into an int, so there is no performance penalty or anything like it.
But, from what you're describing, it sounds like somebody has #defined INCORRECT_FRAME to 0 elsewhere. You should put something like the following in the line above it:
#ifdef INCORRECT_FRAME
#error Whoops, INCORRECT_FRAME already defined!
#endif
BTW, the #ifndef thingy (for your header files) is called an include guard. :-)