Header guard deactivates IntelliSense within it - c++

Well, let's say I have simple code like that:
#ifndef SYSTEM_CLASS_H
#define SYSTEM_CLASS_H
class SystemClass {
public:
SystemClass();
bool Initialize();
}
#endif
My issue is that everything within the header guard is ommited by IntelliSense. Is it intentional? Is there any way to disable it? I tried to look for solution on SO and Google, but I found nothing. I'm using VS 2012 Express, which recently got 3rd update.

Related

Unable to compile Qt project using qlogvalueaxis.h

I am currently working on a C++ application for controlling an instrument. The instrument output should be displayed using a QChart. For the display I created a Qt user interface with a QChartView widget.
Here is the header file for the display class:
#pragma once
#include <QWidget>
#include "QtCharts\qchart.h"
#include <QtCharts\qchartview.h>
#include <QtCharts\qscatterseries.h>
#include <QtCharts\qlineseries.h>
#include "ui_ChartsDisplay.h"
#include <qthread.h>
using namespace QtCharts;
class ChartsDisplay : public QWidget
{
Q_OBJECT
public:
ChartsDisplay(QWidget *parent = Q_NULLPTR);
~ChartsDisplay();
private:
Ui::ChartsDisplay ui;
QLineSeries *trace,*retrace,*arbitrarySeriesX,*arbitrarySeriesY;
QChart *chart;
//QLogValueAxis *axisX, *axisY;
void rescaleChart();
public slots:
void SLUpdateChart(float *newValues);
void SLSetupChartDisplay(int type);
void SLResetChart();
void SLUpdateNoise(float** newValues, int size);
};
I need two instances of the ChartDisplay class. One with linear and one with logarithmmic scaling for displaying different data types.
I found a Qt tutorial on using logarithmic axis scaling here:
https://doc.qt.io/qt-5/qtcharts-logvalueaxis-example.html
However, once I include "qlogvalueaxis.h" my programm will no longer compile. I get a long list of syntax errors originating in "qlogvalueaxis.h".
I created a new Qt project and implemented a simple chart with logarithmic scaling using qlogvalueaxis which worked fine.
Also I cleaned the whole project and removed all qt generated files before compiling. The problem still remained.
All necessary libraries are linked and up to date as are the header files.
Some information about the environment:
-Visual Studio 2015, community edition
-Qt framework 5.8
-Operating system is Win 7
Any would appreciate any advice.
Best regards,
T. Krastev
I had a similar (or perhaps the same) problem. I got compile errors indicating that the min() and max() function prototypes were already declared elsewhere, so if this is the case for you simply omit the min and max macros by adding the following before including the QtCharts headers:
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif

AActor *UactorComponent::GetOwner const - pointer to incomplete class type is not allowed

I'm new to UE4 development and I've followed Udemy's Unreal Engine Development course. I have created a new Component on an Actor, named PositionReporter with header PositionReporter.h
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UPositionReporter : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UPositionReporter();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
and code in PositionReporter.cpp being
#include "PositionReporter.h"
// Sets default values for this component's properties
UPositionReporter::UPositionReporter()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UPositionReporter::BeginPlay()
{
Super::BeginPlay();
FString t = GetOwner()->GetActorLabel();
UE_LOG(LogTemp, Warning, TEXT("Position Reporter reporting for duty on %s"), *t);
}
// Called every frame
void UPositionReporter::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
As you can see, I am now trying to call the GetName function on the Pointer to the AActor retrieved through GetObject().
However, as soon as I type "GetObject()->" no autocomplete pops up (as it does in the video) and when I add "GetName()" manually, I get the compiler error "pointer to incomplete class type is not allowed".
What am doing wrong? Am I missing an import or so? I already compared my code to Ben's git repo but can't find any differences. I am on unreal editor 4.16.0!
I noticed another strange thing: When I compile everything from Unreal Engine Editor, it compiles and runs fine. But when I compile it with VS 2017 I get the error, and I also dont get the Autocomplete, which is a real bummer. What am I missing?
Including Engine.h on PositionReporter.h fixes the issue.
#pragma once
#include "Engine.h" // <- This
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PositionReporter.generated.h"
You'll need to give Intellisense some time... As a matter of fact I closed and reopened the solution for it to stop showing the non existing errors and give autocomplete functionality.
NOTE: As is mentioned in other posts, this solution is good to get intellisense autocompleting but isn't the best as it will include a ton of stuff and greatly increase compilation times.
Including the specific .h file would be better, but you need to know what .h to include, and probably you don't know it.
Best solution I found is ditching Intellisense and use Resharper for code autocompletion, it works fast, autocompletes correctly and you don't need to include any extra file.
I would like to point out that including "Engine.h" is going against the IWYU rationale from Unreal 4.15 onwards, because Engine.h is huge and slows down compile time. See the Unreal Documentation for more information on the matter. So although it solves the problem, and there is nothing particularly 'wrong' with doing it - it may not be the best idea.
Another option which is more in line with IWYU would be to include Actor.h in PositionReport.cpp since GetOwner is in the AActor class.
#include "PositionReport.h"
#include "GameFramework/Actor.h" //This is the change in PositionReport.cpp

Visual Studio not building correctly

I've been having two different problems when trying to compile a C++ project today.
Sometimes it won't reflect any of my changes in the new build: If I change some wording on the output or change around actual functionality and compile and hit Start Debugging, it will behave exactly as it did before I made the changes. Hitting Clean or Rebuild Solution fixes this, but it takes about a full minute to compile this. I guess it's not detecting any changes, but in the output window I see it list the file names of files I made changes to...
I'm also getting a lot of "...already defined in main.obj" errors (one for every function and variable) whenever I try to use a header file or define a function outside of a class. Renaming the functions lets it compile once, but then the second compile will bring up the errors again. It kinda works if I just define the class in a .cpp file, don't use a header file, and don't use any functions outside of the class.
The project is an open-source program I downloaded the other day to mess with (I'm building a bot to control it). I didn't have the first problem until today, but the second one's always been happening. All I've done is add a file (two if you count both Bot.cpp and Bot.h); Bot.cpp includes Bot.h and some files from the program, and the program's main.cpp includes Bot.cpp.
I'll post some code I guess, but I can't find anything wrong with what I'm doing. I'm wondering if there's something I need to do to the existing files? (there were VS solution files included with the project that I used to open it, since VS Express doesn't help you create projects from existing code.)
//Bot.h
#ifndef _Bot_h_
#define _Bot_h_ 1
#include <string>
class Bot{
private:
uint32 inputs = 0;
bool active = false;
public:
Bot(){};
~Bot(){};
void Start();
void Stop();
void Run();
void Wait(int seconds);
void Press(int buttons);
};
#endif
//Bot.cpp
#ifndef _Bot_cpp_
#define _Bot_cpp_ 1
#include "main.h"
//Some other project files included between these
#include "Bot.h"
using namespace std;
void Bot::Start(){
if (active == false){
active = true;
Run();
}
}
void Bot::Stop(){
active = false;
}
void Bot::Run(){
while (active == true){
printf("Has my code updated?\n");
Wait(2);
}
}
//There are more functions defined here
#endif
All I've really done in the original source code is include Bot.cpp at the bottom of the list of includes in the main.cpp file, and then add a call to create the class. I'm a little out of practice with C/C++ so maybe it's something simple. I'm also bad at writing posts like this so if anything needs clarified I'll try to help.

Visual Studios 2013 indenting code

It's not necessary I fix this 'issue' since it's a more aesthetic thing. I was just wondering if it's possible to indent code that comes under the "public:" deceleration after indenting the deceleration itself.
So it would look like this:
class Myclass{
public:
void test(){
}
}
At the moment the void part would be directly underneath the public modifier. I have looked through the formatting setting and yet cannot find how to do this.
In visual studio open Tools/Options. In the menu on the left choose Text Editor->C/C++->Formatting. There you can change a lot of things like indentation.

Defining a preprocessor directive for windows 7

I am making use of SetDllDirectory() and wants to know how can i define a directive for windows 7 HP 64 bit i am thinking something like this :
In preprocessor directives :
Add WIN7
In the .cpp i was thinking to add something like
#ifndef WIN7<- where the function is used
SetDllDirectory();
#endif
but as soon as i add the statements the SetDllDirectory becomes commented.
And this is something i tried with , i added WIN7 in the preprocessor definations and added :
#if defined(__WIN7__)
if (regkeyExists) {
if (regkey->HasValue("LibPath")) {
regkey->QueryValue("LibPath", value);
if (!value.empty()) {
wxSetEnv("ABCLib", value);
SetDllDirectory(value.c_str());
}
}
}
SetDllDirectory("C:\\Program Files\\ABC\\ABCProject\\lib");
#endif
Is this the right to declare windows 7
Thanks
You don't want to define your own macro to detect Windows 7, use the ones provided by Microsoft - wrap your Win7 only code in:
#ifdef _WIN32_WINNT_WIN7
xyz()
#endif
If you do create your own, you must define it when you want to compile for Windows 7, it seems that you're hiding the SelDllDirectory() function - #ifndef means "if not defined" so if WIN7 macro is not defined anywhere, then you get that function.
How about NTDDI_VERSION or _WIN32_WINNT?