I am getting an "Expected class-name before , or ; and I dont quite get how to fix it.
Here is where the error is:
class FXHost : public CPLAT::CP_Application, public CPLAT::CP_M_Listener
{
The file is FXHost.h and CPLAT:: is obviously a namespace where CP_Application and CP_M_Listener are.
I dont see why this would be wrong. This code ran fine in Metrowerks (without the CPLAT::) but in XCode CPLAT is needed due to the way the code was written by the previous developer.
Can anyone shed some light on this error?
UPDATE: Here is a sample of the CP_Application class
template <class DOC_POLICY, class PRINT_POLICY, class UNDO_POLICY>
class CP_EXPORT CP_Application : public CP_Application_Imp
{
public:
typedef DOC_POLICY DocPolicyType;
typedef PRINT_POLICY PrintPolicyType;
typedef UNDO_POLICY UndoPolicyType;
CP_Application();
virtual ~CP_Application() throw();
It looks like the compiler hasn't seen the class declaration for the two parent classes. The first thing I would check are your include directives. Are you sure you're including header which defines the classes CP_Application and CP_M_Listener?
Related
I have the kinda weird problem which is already described in nested class inherits from nested class, but i start to get a little bit desperate by now.
I have 4 classes in 2 different files (i don't think that really matters), I'll also cut out the non-important stuff from the classes for a better overview
Request.h (With class Request and BaseCtx)
#ifndef REQUEST_H
#define REQUEST_H
#include <string>
#include <map>
class Request
{
public:
Request() {};
Request(Request &orig) {};
class BaseCtx {};
~Request();
/* ... More methods and functions */
private:
/* ... More methods and functions */
};
#endif
Then there is my inherited class in p_TuStRequest.h (TuStRequest and TuStCtx)
#ifndef P_TU_ST_REQUEST_H
#define P_TU_ST_REQUEST_H
/*#include "Request.h"*/
class TuStRequest : public Request {
public:
TuStRequest() {};
TuStRequest(TuStRequest &orig);
TuStRequest(std::string requestData) {};
class TuStCtx : public Request::BaseCtx {
std::string teid;
};
private:
};
#endif
And my compiler (gcc version 4.2.4 (Gentoo 4.2.4-r01.16 p1.1) tells me the following:
p_TuStRequest.h:14: error: expected class-name before '{' token Makefile:431: recipe for target 'p_TuStController.o' failed
For the ones which are not that familiar with compiler versions, vers. 4.2.4 is a little bit before c++11 support (so basically C++98)
Is this some kind if problem because the compiler (which I can't upgrade) is that old and does not support this or did I do something wrong fundamentally?
If this really is a compiler problem, is there a way around it? If i remove the nested class in TuStRequest everything builds fine, but i would need a second structure to prevent the usage of voidpointers (I really don't want to use voidpointers for the context)
PS: Yeah i know, some stuff is still missing (Copy Constructor and so on..) but that shouldn't be the issue here.
I'm working on a project in c++ and I stuck with no idea what is wrong. I've writen 4 classes and everything looked fine during work (under visual studio 2010). VS 'saw' all the definition, i could use auto-fill and sudgestions, but when I tried to compile the project it sudennly went blind. It's like I didnt include headers or something (which I did). The strange thing is there is no problem with working with those classes on VS (i can ctrl+space for hint, list of attributes and methods and all that stuff) but when i try to compile it says "ClassName" is not a type.
Quick sample of problem below:
ProButton.cpp:
#include "ProButton.h"
using namespace pGUI;
ProButton::ProButton( ... )
: ProControl( ... )
{
...
}
ProButton.h:
#ifndef __PRO_BUTTON__
#define __PRO_BUTTON__
#include <string>
#include "ProControl.h"
namespace pGUI
{
class ProButton :
public pGUI::ProControl
{
public:
//attributes
...
public:
//methods
...
};
}
#endif
but compiler says:
Error 291 error C2653: 'ProButton' : is not a class or namespace name
for this line in ProButton.cpp: ProButton::ProButton( ... )
It also says:
Error 23 error C2039: 'ProControl' : is not a member of 'pGUI'
Error 24 error C2504: 'ProControl' : base class undefined
and all similar errors for whole project. I have no idea what is wrong. Looks like my VS broke :D
Of course those (...) means there is code there, just not that important for now. I can upload all solution somewhere fi it will help.
edit//
About namespaces, all header files (classes declaration) are defined in namespace with:
namespace pGUI{
class ProClass
{
};
}
all definitions for these classes (in ProClass.cpp) are using:
using namespace pGUI;
at the beginning.
I think the problem is with order of including files.
Im not sure how this is supposed to be done. So far i have 4 classes that:
class ProGUI:
has a pointer to ProContainer
includes: ProContainer and ProControl
class ProContainer:
has pointers to: ProGUI and ProControl
class ProControl:
has a pointer to ProContainer
includes ProButton
is a base class for ProButton
class ProButton:
is a sub-class of ProControl
Those classes also uses irrlicht library and I'm not sure where to include it.
I had it included in my main file just before #include "ProGUI.h". This is also the only include in main. ProGUI.h .
//EDIT 2 -> solved
It was a problem with includes. I needed to rethink my inclusion order and add some forward declarations. Anyway that all seemed strange and took me a lot of time to figure i out. Thx for help. :)
It seems that you are using following statement:
using namespace pGUI;
Just before the class declaration:
class ProControl
{
};
Instead of using following approach:
namespace pGUI
{
class ProControl
{
};
}
The using namespace, as it says uses a namespace. You need to explicitly put something a namespace using namespace keyword followed by braces!
using namespace pGUI informs the compiler that it should look in the pGUI namespace to resolve existing names.
To declare or implement something in a namespace you need to be more specific. with either:
namespace pGUI
{
ProButton::ProButton( ... ) : ProControl( ... )
{
...
}
}
or:
pGUI::ProButton::ProButton( ... ) : ProControl( ... )
{
....
}
Personally, I consider any use of using namespace to be a lazy programmer hack that completely defeats the point of namespaces. But I digress. :)
I am porting a C++ project to Mac using Xcode. Now I have a class that is declared as following:
namespace poi {
class AesCipher : public SymetricCipher {
public:
AesCipher();
virtual ~AesCipher ();
//more method declarations here...
};
}
Yet Xcode will present me an error for the line of the public: statement:
C++ requires a type specifier for all declarations
I assume this has to do with the namespace but I'm not that experienced with C++.
I have no idea what this error is trying to say to me. Maybe someone has seen such an error before and could just point me in the right direction what kind of mistake I might have made.
Goal: To inherit from a class with 2 template parameters.
Error
Error error C2143: syntax error : missing ',' before '<'
The Code
template< typename Type >
class AssetManager : public IsDerivedFromBase< Type, Asset* >
{
// Class specific code here
};
Things you need to know: Asset is a class that just wraps a char* with a getter/setter and IsDerivedFromBase will be used to basically test wether or not Type is a derivative of Asset. These sets of classes are isolated in there own small scale visual Studio 2012 project and will be integrated into the main project once all the functionality has been tested thoroughly.
Some Edits based on Comments
Thank you for the help so far, I really appreciate it. Here are some more specifics:
IsDerivedFromBase.h
#ifndef ISDERIVEDFROMBASE_H
#define ISDERIVEDFROMBASE_H
#include< iostream > // For access to NULL
namespace Fenrir
{
template< typename Type, typename Base >
class IsDerivedFromBase
{
private:
static void Constraints( Type* _inheritedType )
{
Base* temp = NULL;
// Should throw compiler error if
// this assignment is not possible.
temp = _inheritedType;
}
protected:
IsDerivedFromBase( ) { void( *test )( Type* ) = Constraints; }
};
}
#endif
Note: This class was based off of a class I read about in an article. I have since found a better way to achieve the desired result; however, I wish to understand where this error is stemming from.
AssetManager.h"
#ifndef ASSETMANAGER_H
#define ASSETMANAGER_H
#include "IsDerivedFromBase.h"
namespace Fenrir
{
template< typename Type >
class AssetManager : public IsDerivedFromBase< Type, Asset* >
{
// Class specific code
};
}
#endif
Keeping class specific code to a minimum to keep this post as neat as possible, if more info is needed just let me know and I can add it in :).
That error message is common when the compiler encounters an identifier that it did not expect, so a first guess would be that IsDerivedFromBase is not known to the compiler at the time (maybe you did not include the appropriate header?). Alternatively, if IsDerivedFromBase is not a template, the compiler would also expect a , (or ;) after it.
Solved my issue which was interestingly silly. So due to a comment (from Jesse Good) I took a quick look at my includes. Since this was a small "whip it up quick" kind of project I didn't really pay much attention to them. I don't know exactly where the error was occuring, but I found out that AssetManager did not know about IsDerivedFromBase so I set up the following code block to just solve that issue without having to write a bunch of
#include statements everywhere!
// Contact point houses all of the include files
// for this project to keep everything in one place.
#ifndef CONTACTPOINT_H
#define CONTACTPOINT_H
#include "Asset.h"
#include "Sprite.h"
#include "IsDerivedFromBase.h"
#include "GenericManager.h"
#include "AssetManager.h"
#endif
Now I just include this in every header and all is well. I've been programming C++ for a little over a year now and never ran into this, a good lesson to learn for anyone new programming.
Thanks for your help everyone : )
Maybe I missed something, but I cant figure out why Visual Studio 2008 isn't seeing the rdbuf() procedure. Here is my code:
16. #include "DebugBuffer/BufferedStringBuf.h"
17.
18. BufferedStringBuf debug_buffer(256);
19. std::cout.rdbuf(&debug_buffer);
The BufferedStringBuf class is from this page: http://www.devmaster.net/forums/showthread.php?t=7037
Which produces the following error:
...src\main.cpp(19) : error C2143: syntax error : missing ';' before '.'
All I want to do is redirect std::cout to the Visual Studio Output window using OutputDebugString()..
You're not allowed to have executable statements at file-level scope. You can declare variables, but you can't call functions as standalone statements. Move your code into a function (such as gf's answer demonstrates), and you should have no problem.
Using the example class given on that site i don't have any problem:
#include <iostream>
#include "DebugBuffer/BufferedStringBuf.h"
class DbgBuf : public BufferedStringBuf {
public:
DbgBuf() : BufferedStringBuf(255) {}
virtual void writeString(const std::string &str) {}
};
int main()
{
DbgBuf debug_buffer;
std::cout.rdbuf(&debug_buffer);
}
Note that you have to create an instance of a class that derives from BufferedStringBuf because BufferedStringBuf::writeString() is pure virtual, thus making it an abstract class - abstract classes can't be instantiated.