syntax error : missing ';' before identifier 'iDlg' - c++

I am trying to get a dialog box [import] to launch from another dialog box [baseline].
I am including the required ".h" files however I am simply not able to create an instance of the import class. The error I get is this:
Error 1 error C2146: syntax error : missing ';' before identifier 'iDlg' h:\shaunak\projects\sar_ccd\sar_ccd\baseline.h 202 1 Sar_CCD
The line of code that causes this [baseline.h]:
#include "Markup.h"
#include<stdio.h>
#include<math.h>
#include "baseline_func.h"
#include "resource.h"
#include "Functions.h"
#include <stdlib.h>
#include "Sar_CCDDoc.h"
#include "Sar_CCDView.h"
#include <vector>
#include "MemAlloc.h"
#include "ReadFiles.h"
#include<vector>
#include<map>
#include "afxwin.h"
#include "import.h"
#include "Geocode.h"
**<SNIP: Taking out the irrelevant lines>**
afx_msg void OnDestroy();
virtual void PostNcDestroy();
afx_msg void OnBnClickedNxtBase();
CButton nextBaseline;
import iDlg; //doesnt work!
CGeocoding cx; //works!!!
};
However, if I create and instance of another class [Geocoding] using the same sysntax like so, it works fine:
#include "Geocoding.h"
CGeocoding cx;
Please help me figure out why.
Full code:
baseline.h: http://freetexthost.com/on06wref6c
import.h: http://freetexthost.com/x4e4dkwrve

In Visual Studio there is a keyword import or #import rather used to import a COM DLL and is used for other things as well. I guess you are experiencing a name collision there.
In order to get around it place your class import in a namespace
import.h
namespace myimport
{
class import : public CDialog {
...
};
};
import.cpp
namespace myimport
{
...
};
then when you use it
myimport::import iDlg;
that should solve the issue, although renaming it to something else than "import" would be the better way to go.

import is not a keyword or type in C++. Therefore you get a syntax error because the compiler doesn't recognize import.
To create an instance of another class you have to properly declare it, e.g.:
class baseline : public CDialog
{
// ...
CDialog *iDlg; // Pointer to imported dialog
};
Remember to initialize the pointer to the actual dialog.

Related

CreateWindow class method throwing expected a type specifier - windows.h

Take the following code:
# pragma once
// Windows specific files
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include "IOS.h"
namespace PlatformGameEngine
{
class OSWindows : public IOS
{
public:
virtual void CreateWindow( const WindowProperties windowProperties ) override;
};
}
If i remove the #include <windows.h> the code compiles fine. If i keep it in, I get an error pop up under the virtual void CreateWindow part...
expected a type specifier
What's going on here? How do i solve it?
CreateWindow is an evil macro. If you include the header that defines it, you can't use the name for any other purpose.
Either stop supporting Microsoft or, if you really must do that, choose a different name for your function. Or maybe add #undef CreateWindow and hope for the best.

C++ compilation error when adding windows.h

I need to write small tool in C++
I've never used C++ as programming language before (I have couple years of Java dev experience) and .NET
I've started a new project in VS , when I am adding in my Header file of my class
#include <windows.h> I am getting the following error:
Error 1 error C2143: syntax error : missing ';' before '*' c:\program files\microsoft sdks\windows\v7.0a\include\servprov.h 96 1 CppLog
For now my class even doesn't have any real functions and looks like
in header
class TheTool
{
public :
void Foo();
};
in cpp
void TheTool::Foo(){};
and the project doesn't get compiled.
plz any suggestions ? Maybe a compiler doen't set up good ?
this is how the Header file looks like
#pragma once
#include "stdafx.h"
#include <stdio.h>
//#include <Windows.h>
//#include <winuser.h>
//#include <windowsx.h>
//#include <time.h>
class TheTool
{
public :
void Foo();
};
When I am uncommenting the include I am starting to get this compilation error.
BTW , how can i know the compiller setting ?

error C2504: 'ios' : base class undefined

I am trying my hands on sample codes from a book, and so I am not entirely sure what I may have wrong in the header file I have so far.
I keep getting the following error messages.
Error 2 error C2061: syntax error : identifier 'streambuf'
Error 1 error C2504: 'ios' : base class undefined
Error 5 IntelliSense: identifier "streambuf" is undefined
// StdAfx.h HEADER FILE
**************************
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include <iostream>
#include <strstream>
#include <iomanip>
#include <ios>
#include <stdio.h>
#include <tchar.h>
#include "targetver.h"
// Conios HEADER FILE
**************************
#include "Stdafx.h"
class Conios :virtual public ios{
protected:
public:
Conios(void);
~Conios(void);
Conios(streambuf* Buffer);
};
ios is in the std-namespace. So either use use namespace std; or extend from std::ios instead of just ios.
If you are using use namespace use it only in your implementation-files like *.cpp or *.cxx, do not write use namespace ... your header files - ever!.
And the same goes for streambuf.

Expected Class-name before { token

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

C++ Use of undeclared identifier 'make_unique'

I am keep on getting the following error when I build,
use of undeclared identifier 'make_unique'
m_planet = make_unique();
My Header File which gives out the error,
#include "planet.h"
#include <memory>
using namespace std;
class PlanetBuilder
{
public:
PlanetBuilder();
virtual ~PlanetBuilder();
void createNewPlanetProduct() {
m_planet = make_unique<Planet>();
}
protected:
unique_ptr<Planet> m_planet;
};
#endif // PLANETBUILDER_H
I am running QtCreator 3.6.0 , tried on both Mac and Windows platforms and the error is consistent.. where am I going wrong?
make_unique requires #include <memory>
But since you have done that, I would think you are not using C++14 or above.
Try adding following flag on your make file.
-std=c++14
For current QT which is 5.7 I'm using a #include .
By following a link bellow you find out more. QScopedPointer link