Source SDK Compile Errors - c++

I am making a Counter Strike mod and during compiling I am getting some errors:
Panel.cpp(715): error C2248: 'CInput::CVerifiedUserCmd' : cannot access private class declared in class 'CInput'
1> \SDK\\game\\client\\input.h(238) : see declaration of 'CInput::CVerifiedUserCmd'
1> \SDK\\game\\client\\input.h(39) : see declaration of 'CInput'
Line 715:
CInput::CVerifiedUserCmd* ver = NULL;
Declaration:
class CVerifiedUserCmd
{
public:
CUserCmd m_cmd;
CRC32_t m_crc;
};
How do I fix this?

You're probably trying to use a private inner class:
class A
{
class B
{
};
};
Simply make the class public if you wish to use it outside:
class A
{
public:
class B
{
};
};
EDIT:
If the class is private and it's part of a 3rd party lib, you're probably doing it wrong. Look for a different solution to your problem, it was made private for a reason.

Assuming that was your code put class
CVerifiedUserCmd
to public section of the outer class. Otherwise you cannot use CVerifiedUserCmd since it is private inner class.

You probably can't (unless you want to edit the engine itself) - look for a better solution to your problem. Basically, don't try to manually instantiate CInput::CVerifiedUserCmd.

Related

Inherit from Nested class inside inherited class

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.

How to declare a new class in the header and define it in the source file without this errors?

I'm on the situation where I want to create a new class and then use it in another created class (C++), but without using different header or source files: both classes shall be in the same place, one way or another. The main class shall contain only a pointer to the "child" class.
Now I know that in many cases is perfectly possible to define a class in the header file. In fact, if one wants to not just set a pointer to that "child class", but actually use one of its methods already in the header file (e.g., for inline methods), one would actually have to define it in the source file:
class ChildClass
{
public:
bool myFunctions() { return true; }
}
class MainClass
{
private:
ChildClass* poChildClass;
inline bool getResult() { return poChildClass->myFunctions(); }
}
But let's suppose I want just to have that pointer there, without any call to my ChildClass' methods, so I should be able to only declare the ChildClass and later define it in the same .cpp file as MainClass is defined:
//in .hpp
class ChildClass;
class MainClass
{
private:
ChildClass* poChildClass;
}
//in .cpp
class ChildClass
{
public:
bool myFunctions() { return true; }
}
//etc.
In a first moment I don't know what could be there of a problem. But in trying to do so with one of my classes in particular (which is based on Qwt's QwtPlotPicker class), I get some compile errors (in this last version):
error: undefined reference to `vtable for Picker'
The error points out where in the following code (in the .cpp):
class Picker : public QwtPlotPicker
{
Q_OBJECT
public:
Picker( QWidget* canvas ) :
QwtPlotPicker( canvas ) //Here lies the error the compiler says
//...
So what is the problem? What do I get this "undefined reference to 'vtable'" problem?
Thanks for any help,
Momergil
This is a problem I have had forever when using QT. Any class that has the Q_OBJECT macro in it MUST be listed in the HEADERS before running qmake (as far as I can tell). This may even mean putting the .cpp file in the HEADERS section.

how to inherit a #include class?

I have 4 files,
HomeScene.h
HomeScene.cpp
Options.h
Options.cpp
both the *.h files have the other *.h included.
Now I am trying to inherit HomeScene.h in Options.h
class OptionScene : public cocos2d::CCLayerColor,HomeScene
the above line gives so many errors.
class OptionScene : public cocos2d::CCLayerColor
the above line has no errors
I have a static bool var; in my HomeScene.h
which I am trying to use directly in my options scene.
Why do you need to include Options.h in HomeScene.h ? If OptionScene is the type derived from HomeScene, then I don't know why would you need to do that.
In case you just need to declare pointer / reference to the type declared in Options.h, you could use forward declaration.
Options.h
#include "HomeScene.h"
class OptionScene
{
// ...
};
HomeScene.h
class OptionScene; // forward declaration
class HomeScene
{
OptionScene* o;
};
If this is your problem, then this question will help you: When can I use a forward declaration?

How to implement an interface in managed c++?

Here's interface that I have declared:
[ServiceContract]
public interface class IShedluer
{
[OperationContract]
array<Object^>^ GetResult(UInt64 taskId);
}
Here's the class that is trying to implement it:
ref class MyShedluer:IShedluer
{
Shedluer ^shedluer;//this is NOT MyShedluer
public:
MyShedluer(void);
array<Object^>^ GetResult(UInt64 taskId)
{
return shedluer->GetResult(taskId);
}
}
When I'm trying to compile this, I'm getting
Error 15 error C3766: 'MyShedluer' must provide an implementation for
the interface method 'cli::array<Type> ^IShedluer::GetResult(unsigned __int64)'
d:\users\menkaur\documents\visual studio 2010\projects\MyProject\
\kernel\MyShedluer.h 78 1 MyProject.Kernel
Why am I getting this?
the correct syntax for implementing an interface is to add virtual:
ref class MyShedluer:IShedluer
{
public:
virtual array<Object^>^ GetResult(UInt64 taskId);
}
Also the compiler tells you this, look at your warnings as well:
warning C4488: 'MyShedluer::GetResult' : requires 'virtual' keyword
to implement the interface method 'IShedluer::GetResult'

Expected class name before ',' or ';'

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?