The compiler is giving me the following complaints about the following class:
class AguiWidgetBase
{
//variables
AguiColor tintColor;
AguiColor fontColor;
//private methods
void zeroMemory();
virtual void onPaint();
virtual void onTintColorChanged(AguiColor color);
void (*onPaintCallback)(AguiRectangle clientRect);
void (*onTintColorChangedCallback)();
public:
AguiWidgetBase(void);
~AguiWidgetBase(void);
void paint();
void setTintColor(AguiColor color);
AguiColor getBackColor();
};
Warning 13 warning C4183: 'getBackColor': missing return type; assumed to be a member function returning 'int' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 26
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 11
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 11
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 12
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 12
Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 26
Error 12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 26
Error 1 error C2146: syntax error : missing ';' before identifier 'tintColor' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 11
Error 10 error C2146: syntax error : missing ';' before identifier 'getBackColor' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 26
Error 4 error C2146: syntax error : missing ';' before identifier 'fontColor' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 12
Error 8 error C2061: syntax error : identifier 'AguiRectangle' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 17
Error 7 error C2061: syntax error : identifier 'AguiColor' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 16
Error 9 error C2061: syntax error : identifier 'AguiColor' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\AguiWidgetBase.h 25
This should be working, I'm including the headers for those classes.
This is the h file:
//integer Point class
class AguiPoint {
int x;
int y;
public:
int getX();
int getY();
void setX(int x);
void setY(int y);
void set(int x, int y);
AguiPoint(int x, int y);
AguiPoint();
std::string toString();
std::string xToString();
std::string yToString();
};
//floating version of Agui Point
class AguiPointf {
float x;
float y;
public:
float getX();
float getY();
void setX(float x);
void setY(float y);
void set(float x, float y);
AguiPointf(float x, float y);
AguiPointf(AguiPoint p);
AguiPointf();
std::string toString();
std::string xToString();
std::string yToString();
};
//Integer rectangle class
class AguiRectangle {
int x;
int y;
int width;
int height;
public:
bool isEmpty();
int getTop();
int getLeft();
int getBottom();
int getRight();
AguiPoint getTopLeft();
AguiPoint getBottomRight();
};
class AguiColor {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
void verifyColorBounds();
public:
AguiColor(int r, int g, int b, int a);
AguiColor(float r, float g, float b, float a);
AguiColor();
int getR();
int getG();
int getB();
int getA();
};
Thanks
I include the main header in the WidgetBase and the main header includes the base types before it includes the widgetbase
It seems you are not including the headers in the right order.
C++ is very sensitive to the order in which identifiers are declared. The compiler will process a source file (and any #include-s it finds along the way) in a sequential order and for every (non-builtin) identifier, the compiler must have seen a declaration before you can use it.
If you already have the headers included i'd guess you need to fully qualify the names because of a namespace or that Aguiwidgitbase is in the wrong namespace? either way check the namespaces in the headers you included
Check header files and namespaces. You may also need forward declarations.
You may have a problem of include dependencies. Header guards preventing multiple definition (#pragma once, or #ifndef HEADER #define HEADER) can block your inclusion.
One answer can be forward declarations... for pointers to class, not for class members though (need to know storage size at compile time).
Related
This question already has answers here:
Resolve build errors due to circular dependency amongst classes
(12 answers)
Closed 2 years ago.
Have two files:
CIoHandler.h
#pragma once
#include "CSession.h"
class CIoHandler
{
public:
CIoHandler();
~CIoHandler();
void AuthenticateUser();
void ConvertUnicodeToAscii();
void DoNTLMAuth();
void GetAndSetSocket();
void GetElevatedToken();
void GetHeaderMessage();
void GetUserNameW();
void HandleOperatorMessage();
void Init(CSession *cSession);
void IsLocalAccount();
int IsLoopBack();
void IsSPNFQDNName();
int IsSPNLocalInterface();
void IsSPNPresentInRegistry();
void IsTimedOut();
void IssueReadFromSocket();
void OnDataFromSocket();
void OnReadFromPipeCompletion();
void ParseAndValidateAccount();
void ProcessAuthenticationLine();
void ProcessCommandLine();
void ProcessDataFromSocket();
void ReadRegistryKey();
void SendDetailsAndAskForLicense();
void SendMessageToClient();
void SendTerminateString();
void SetPrivilege();
void WriteMessageToClientDirectly();
void WriteToClient();
void WriteToServer();
void WriteToSocket();
};
CSession.h
#pragma once
#include "CIoHandler.h"
class CSession
{
private:
CIoHandler* _CIoHandler;
public:
CSession();
~CSession();
void CollectPeerInfo();
void FreeInitialVariables();
void GetRegistryValues();
void Init();
void IsAnAdministratorOrMember();
void SecpSetIPandPort();
void Shutdown();
void WaitForIO();
};
When compiling with Visual Studio 2019 get the following errors:
CSession.h(8,13): error C2143: syntax error: missing ';' before '*'
CSession.h(8,13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
CSession.h(8,26): error C2238: unexpected token(s) preceding ';'
CIoHandler.h(16,22): error C2061: syntax error: identifier 'CSession'
CIoHandler.h(16,22): error C2061: syntax error: identifier 'CSession'
Removing
#include "CIoHandler.h"
private:
CIoHandler* _CIoHandler;
From CSession.h it compiles
What do I need to so I can use CIoHandler in CSession class definition
You have a cyclic include dependency. To break the cycle replace
#include "CIoHandler.h"
with a forward declaration.
class CIoHandler;
Im having a compilation error and i cant figure why.
I have enum declaration on the .h file and the .cpp file suppose to use it inside stringToEnum() function
this is the .cpp file
#include "A.h"
A::A(void)
{
}
A::~A(void)
{
}
values A::stringToEnum (string inputString) {
if (inputString == "string1") return val1;
if (inputString == "string2") return val2;
}
this is the header file
class A
{
public:
A(void);
~A(void);
private:
enum values{
val1,
val2,
val3,
val4
};
values stringToEnum (string inputString);
};
this is the error I get:
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C2143: syntax error : missing ';' before 'A::stringToEnum'
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C2556: 'int A::stringToEnum(std::string)' : overloaded function differs only by return type from 'A::values A::stringToEnum(std::string)'
1> c:\users\documents\visual studio 2010\projects\A.h(22) : see declaration of 'A::stringToEnum'
1>c:\users\documents\visual studio 2010\projects\A.cpp(25): error C2371: 'A::stringToEnum' : redefinition; different basic types
1> c:\users\documents\visual studio 2010\projects\A.h(22) : see declaration of 'A::stringToEnum'
I will be happy for some guidance.
thanks
Since values is contained in A, you need to qualify the name:
A::values A::stringToEnum (string inputString) {
//...
Please have a look at the following code,
Stack.h
template <typename T>
class Stack
{
public:
Stack(int number)
{
maxSize = number;
top = -1;
stackData = new T*[maxSize];
}
~Stack()
{
delete [] stackData;
}
int count()
{
}
bool isEmpty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
bool isFull()
{
if(top== (maxSize-1))
{
return true;
}
else
{
return false;
}
}
*T pop()
{
if(!isEmpty())
{
return stackData[top--]; // Remove Item From Stack
}
}
*T peek()
{
T *peekData = &stackData[top];
return peekData;
}
void push(T *pushValue)
{
if(!isFull())
{
stackData[++top] = pushValue;
}
}
private:
int maxSize;
T ** stackData;
int top;
};
Main.cpp
#include <iostream>
#include "Stack.h"
#include <iostream>
using namespace std;
int main()
{
int i = 0;
Stack<double> doubleStack(5);
double doubleValue = 1.1;
cout << "pushing elements into the stack" << endl;
while(i<5)
{
doubleStack.push();
}
system("pause");
return 0;
}
When I run this code, I get the following error.
1>------ Build started: Project: CourseWork2, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(48): error C2146: syntax error : missing ';' before identifier 'pop'
1> c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(74) : see reference to class template instantiation 'Stack<T>' being compiled
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(48): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(49): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(54): warning C4183: 'pop': missing return type; assumed to be a member function returning 'int'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(56): error C2146: syntax error : missing ';' before identifier 'peek'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(60): warning C4183: 'peek': missing return type; assumed to be a member function returning 'int'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(48): error C2146: syntax error : missing ';' before identifier 'pop'
1> c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\main.cpp(11) : see reference to class template instantiation 'Stack<T>' being compiled
1> with
1> [
1> T=double
1> ]
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(48): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(49): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(49): warning C4183: 'pop': missing return type; assumed to be a member function returning 'int'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(56): error C2146: syntax error : missing ';' before identifier 'peek'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(57): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\stack.h(57): warning C4183: 'peek': missing return type; assumed to be a member function returning 'int'
1>c:\users\yohan\documents\visual studio 2010\projects\coursework2\coursework2\main.cpp(18): error C2660: 'Stack<T>::push' : function does not take 0 arguments
1> with
1> [
1> T=double
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Intellelisense is not identifying any method except isFull(), count() and isEmpty(). I can't code the rest because of this!
Why is this? Please help!
You put * at wrong place in function syntax:
Update:
*T pop()
*T peek()
To:
T* pop()
T* peek()
You put the asterisk in the wrong spot. It should be:
T *pop() {
//implementation
}
and
T *peek() {
//implementation
}
I have the following code :
class v8NMatch : public V8Wrap<Match, v8NMatch>
{
public:
static v8::Persistent<v8::FunctionTemplate> s_ct;
static void Init(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> IsSuccess(Arguments& args);
v8NMatch(const v8::Arguments& args);
};
It tells me I have a syntax error at the identifier Arguments.
If I put the const keyword before Arguments, I have 2 errors :
missing type specifier - int assumed. Note: C++ does not support default-int
syntax error : missing ',' before '&'
Any clue ?
IsSuccess is defined without the v8::Arguments.
1 #include"unmanaged.h"
2 #include"stdafx.h"
3 using namespace std;
4 _gc class Mclass
5 {
6 private:
7 string Mx;
8 cppclass * obj;
9 public:
10 Mclass();
11 ~Mclass();
12 string native();
13 };
when buliding this throws
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int and
error C2143: syntax error : missing ';' before '
the content of unmanged.h is
#include"stdafx.h"
#include<string>
#include<iostream>
using namespace std;
class cppclass
{
private:
string x;
public:
cppclass();
~cppclass();
string native();
};
You need two underscores in __gc. See msdn.