I have create this squareList class I when I compile it it give me to many errors I don't know can someone help me to resolve those error
update: I comment all my code after ~square_list(){} and every error pinpoint to list data;
///#include "LinkedList.hpp"
#include <vector>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <list>
#include <iterator>
template <typename T_>
class square_list
{
typedef T_ value_type;
typedef std::size_t size_type;
typedef T_ & reference;
typedef T_ const & const_reference;
typedef T_ * pointer;
typedef T_ const * const_pointer;
typedef T_ * iterator;
typedef T_ const * const_iterator;
typedef std::ptrdiff_t difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//for header vector<pair<itr,unsindINT) header
list<T_> data;
square_list() {}
~square_list(){}
// bool empty(){
// if(this->begin() == nullptr && this->end() == nullptr)
// return 1;
// else
// return 0;
//}
//list<value_type>::iterator begin() {
// return data.begin();
//}
//list<value_type>::iterator end() {
// return data.end();
//}
};
Error 1 error C2143: syntax error : missing ';' before '<'
Error 4 error C2143: syntax error : missing ';' before '<'
Error 7 error C2143: syntax error : missing ';' before '<'
Error 10 error C2143: syntax error : missing ';' before '<'
Error 13 error C2143: syntax error : missing ';' before '<'
Error 16 error C2143: syntax error : missing ';' before '<'
Error 19 error C2143: syntax error : missing ';' before '<'
Error 22 error C2143: syntax error : missing ';' before '<'
Error 25 error C2143: syntax error : missing ';' before '<'
Error 28 error C2143: syntax error : missing ';' before '<'
Error 31 error C2143: syntax error : missing ';' before '<'
Error 34 error C2143: syntax error : missing ';' before '<'
Error 37 error C2143: syntax error : missing ';' before '<'
Error 40 error C2143: syntax error : missing ';' before '<'
Error 43 error C2143: syntax error : missing ';' before '<'
Error 46 error C2143: syntax error : missing ';' before '<'
Error 3 error C2238: unexpected token(s) preceding ';' Error 6 error
C2238: unexpected token(s) preceding ';' Error 9 error C2238:
unexpected token(s) preceding ';' Error 12 error C2238: unexpected
token(s) preceding ';' Error 15 error C2238: unexpected token(s)
preceding ';' Error 18 error C2238: unexpected token(s) preceding
';' Error 21 error C2238: unexpected token(s) preceding ';'
Error 24 error C2238: unexpected token(s) preceding ';'
Error 27 error C2238: unexpected token(s) preceding ';'
Error 30 error C2238: unexpected token(s) preceding ';'
Error 33 error C2238: unexpected token(s) preceding ';'
Error 36 error C2238: unexpected token(s) preceding ';'
Error 39 error C2238: unexpected token(s) preceding ';'
Error 42 error C2238: unexpected token(s) preceding ';'
Error 45 error C2238: unexpected token(s) preceding ';'
Error 48 error C2238: unexpected token(s) preceding ';' Error 2 error
C4430: missing type specifier - int assumed. Note: C++ does not
support default-int Error 5 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 8 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 11 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 14 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 17 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 20 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 23 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 26 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 29 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 32 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 35 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 38 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 41 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int Error 44 error C4430:
missing type specifier - int assumed. Note: C++ does not support
default-int Error 47 error C4430: missing type specifier - int
assumed. Note: C++ does not support default-int
it seems the compiler error is caused by the private construtor, this piece of code can compiler, hope it will help,
#include <vector>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <list>
#include <iterator>
using namespace std;
#define nullptr NULL
template <typename T_>
class square_list
{
public:
typedef T_ value_type;
typedef std::size_t size_type;
typedef T_ & reference;
typedef T_ const & const_reference;
typedef T_ * pointer;
typedef T_ const * const_pointer;
typedef T_ * iterator;
typedef T_ const * const_iterator;
typedef std::ptrdiff_t difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//for header vector<pair<itr,unsindINT) header
list<value_type> data;
square_list() {}
~square_list(){}
bool empty(){
if(this->begin() == nullptr && this->end() == nullptr)
return 1;
else
return 0;
}
/*list<T_>::iterator begin() {
return data.begin();
}
list<T_>::iterator end() {
return data.end();
}*/
};
int main()
{
square_list<int> sq_list;
return 0;
}
Your template parameter is T_, but you are referring to something called T which is undefined. Try changing
list<T> data<T>;
to
list<T_> data;
Also, try commenting out everything inside the class declaration and compiling. Then uncomment one line at a time and deal with any errors that appear after adding each line.
The first problem is this line
list<T> data<T>;
it should be
list<T> data;
Those template arguments are unnecessary and syntactically invalid. Also, you haven't defined the template argument T. Did you mean T_ (or value_type rather)?
Also, you need typename in return types of your begin() and end() methods as value_type is a dependent type:
typename list<value_type>::iterator begin();
typename list<value_type>::iterator end();
You can even take advantage of return type deduction:
auto begin() -> decltype(data.begin());
auto end() -> decltype(data.end());
list<value_type> data;
The code's problem is lack of std:: as follows:
std::list<value_type> data;
You also write using namespace std; before the class definition.
Related
I have this code:
#include <array>
#include <iostream>
class ExternalGeometryExtension
{
public:
enum Flag {
Defining = 0,
Frozen = 1,
Detached = 2,
Missing = 3,
Sync = 4,
NumFlags
};
constexpr static std::array<const char *,NumFlags> flag2str{{ "Defining", "Frozen", "Detached","Missing", "Sync" }};
};
int main()
{
std::cout << ExternalGeometryExtension::flag2str[ExternalGeometryExtension::Frozen] << std::endl;
return 0;
}
It compiles fine with:
clang version 5.0.0 and
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
It fails to compile with MSVC2013.
The compilation error is:
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2144: syntax error : 'int' should be preceded by ';' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2146: syntax error : missing ';' before identifier 'flag2str' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2838: 'array<char const *,5>' : illegal qualified name in member declaration [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2143: syntax error : missing ';' before '{' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2334: unexpected token(s) preceding '{'; skipping apparent function body [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod\Sketcher\App\ExternalGeometryExtension.cpp(36): error C2143: syntax error : missing ';' before 'std::array<const char *,0x05>' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod\Sketcher\App\ExternalGeometryExtension.cpp(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod\Sketcher\App\ExternalGeometryExtension.cpp(36): error C2039: 'flag2str' : is not a member of 'Sketcher::ExternalGeometryExtension' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C2144: syntax error : 'int' should be preceded by ';' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C2146: syntax error : missing ';' before identifier 'flag2str' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C2838: 'array<char const *,5>' : illegal qualified name in member declaration [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C2143: syntax error : missing ';' before '{' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
c:\projects\freecad\src\mod\sketcher\app\ExternalGeometryExtension.h(47): error C2334: unexpected token(s) preceding '{'; skipping apparent function body [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2144: syntax error : 'int' should be preceded by ';' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2146: syntax error : missing ';' before identifier 'flag2str' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2838: 'array<char const *,5>' : illegal qualified name in member declaration [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2143: syntax error : missing ';' before '{' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod/Sketcher/App/ExternalGeometryExtension.h(47): error C2334: unexpected token(s) preceding '{'; skipping apparent function body [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
C:\projects\freecad\src\Mod\Sketcher\App\ExternalGeometryExtensionPyImp.cpp(67): error C2039: 'flag2str' : is not a member of 'Sketcher::ExternalGeometryExtension' [C:\projects\freecad\build\src\Mod\Sketcher\App\Sketcher.vcxproj]
Full compiler output here
My questions are:
What I am doing wrong? Why is it not compiling with MSVC2013?
Is there something I can do to make this code work with MSVC2013 without breaking it in the other compilers?
EDIT: I have changed the code so that it is a Minimal, Complete, and Verifiable example as requested by Toby Speight based on the good guess of Diodacus. I cannot produce the error output of that specific code, because I do not have a copy of MSVC2003. I work on an opensource, FreeCAD, which offers Windows support. I use Linux. In any case, the errors in the output correspond to the code I show. This is the output of the AppVeyor test before integration. The code passes the Linux CI fine. I am going to try to make the most of this question, hopping that it is useful for others.
EDIT 2: I have realised that the double bracket initialization has raised some eyebrows. From the example in cppreference:
double-braces required in C++11 prior to the CWG 1270 revision
(not needed in C++11 after the revision and in C++14 and beyond)
Without double braces gcc 4.8 fails.
As per this microsoft devblog, constexpr is one of the C++11 core language features that is not supported in VS 2013. And it is only partially supported in "Nov 2013 CTP."
Well, the code in question does compile with C++17 option:
#include <array>
#include <iostream>
class ExternalGeometryExtension
{
public:
enum Flag {
Defining = 0,
Frozen = 1,
Detached = 2,
Missing = 3,
Sync = 4,
NumFlags
};
constexpr static std::array<const char *,NumFlags> flag2str{{ "Defining", "Frozen", "Detached","Missing", "Sync" }};
};
int main()
{
std::cout << ExternalGeometryExtension::flag2str[ExternalGeometryExtension::Frozen] << std::endl;
return 0;
}
And there is no need to redeclare static variable outside the class.
#Abdullah Tahiri Please use C++11 constructs (as stated in question labels) or go C++17 for all features. But I am afraid MSVC might be problematic with the code. Is there any special reason you cannot use GCC or CLang on Windows ?
I am trying to write a makeshift renderer for the tutorials on
this site. I have two classes SceneObject and RenderComponent. A SceneObject should contain a RenderComponent which should then draw the SceneObject. This is the code:
SceneObject.h
#ifndef _SCENE_OBJECT_H
#define _SCENE_OBJECT_H
#include <GLM/glm.hpp>
#include <GLM/gtc/matrix_transform.hpp>
#include <GLM/gtc/type_ptr.hpp>
#include <vector>
#include <iostream>
#include "..\headers\shader.h"
#include "..\headers\rendercomponent.h"
class SceneObject {
private:
glm::vec3 position;
float *vertices;
RenderComponent* renderComponent;
std::vector<Shader> shaders;
public:
SceneObject(glm::vec3, GLfloat*);
~SceneObject();
bool init();
RenderComponent& getRenderComponent() const;
};
#endif
SceneObject.cpp
#include "..\headers\sceneobject.h"
SceneObject::SceneObject(glm::vec3 pos, GLfloat* objectVertices) {
this->position = pos;
this->vertices = objectVertices;
renderComponent = new RenderComponent(*this);
}
SceneObject::~SceneObject() {}
RenderComponent& SceneObject::getRenderComponent() const {
return *renderComponent;
}
bool SceneObject::init() {
if (!renderComponent->initialize()) {
return false;
}
}
RenderComponent.h
#ifndef _RENDER_COMPONENT_H
#define _RENDER_COMPONENT_H
#include <GLM/glm.hpp>
#include <GLM/gtc/matrix_transform.hpp>
#include <GLM/gtc/type_ptr.hpp>
#include <iostream>
#include "../headers/sceneobject.h"
class RenderComponent {
SceneObject &sceneObject;
public:
RenderComponent(SceneObject&);
RenderComponent(const RenderComponent&);
bool initialize();
void draw();
SceneObject& getSceneObject() const;
};
#endif
RenderComponent.cpp
#include "..\headers\rendercomponent.h"
RenderComponent::RenderComponent(SceneObject& obj)
:sceneObject(obj){}
RenderComponent::RenderComponent(const RenderComponent& ref)
: sceneObject(ref.getSceneObject()){}
bool RenderComponent::initialize() {}
void RenderComponent::draw() {}
SceneObject& RenderComponent::getSceneObject() const {
return sceneObject;
}
The following errors are produced.
Error C2143 syntax error: missing ';' before '&'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';' syntax error: identifier 'SceneObject'
Error C2143 syntax error: missing ';' before '&'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';'
Error C2664 'RenderComponent::RenderComponent(const RenderComponent &)': cannot convert argument 1 from 'SceneObject' to 'const RenderComponent &'
Error C2143 syntax error: missing ';' before '&'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';'
Error C2061 syntax error: identifier 'SceneObject'
Error C2143 syntax error: missing ';' before '&'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';'
Error C2143 syntax error: missing ';' before '*'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';'
Error C2143 syntax error: missing ';' before '&'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2238 unexpected token(s) preceding ';'
From what i understand, the compiler is saying that SceneObject is not a type. I think this where the problem is. Any help is appreciated.
You have sceneobject.h including rendercomponent.h and rendercomponent.h including sceneobject.h. With the include guards one of them doesn't know about the classes defined in the other header.
Remove the include from one or both headers and just forward declare the class(es) instead.
i am trying to make a program that reads from an ini file but in Visual Studio I keep getting compile errors about string identifiers and semicolons in the wrong place. I am not very good at C++ so it's most likely something really simple, but any way here is the code and error list.
INI.h
#ifndef INI_H
#define INI_H
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
string INIreader(const string&, const string&);
#endif
INI_readnwrite.cpp
#include "INI.h"
using boost::property_tree::ptree;
string INIreader(const string& section, const string& name)
{
ptree pt;
read_ini("GameSettings.ini", pt);
string value = pt.get<string>("section.name");
return value;
}
mainCode.cpp
#include "INI.h"
using namespace std;
int main()
{
string sec = "gameSettings";
string val = "resXY";
cout << INIreader(sec, val);
}
And here is the error list
error// file// line//
error C2872: 'string' : ambiguous symbol maincode.cpp 18
error C2146: syntax error : missing ';' before identifier 'sec' maincode.cpp 18
error C2065: 'sec' : undeclared identifier maincode.cpp 18
error C2872: 'string' : ambiguous symbol maincode.cpp 19
error C2146: syntax error : missing ';' before identifier 'val' maincode.cpp 19
error C2065: 'val' : undeclared identifier maincode.cpp 19
error C2065: 'val' : undeclared identifier maincode.cpp 20
error C2065: 'sec' : undeclared identifier maincode.cpp 20
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ini_readnwrite.cpp 6
error C2872: 'string' : ambiguous symbol ini_readnwrite.cpp 6
error C2146: syntax error : missing ';' before identifier 'INIreader' ini_readnwrite.cpp 6
error C2143: syntax error : missing ',' before '&' ini_readnwrite.cpp 6
error C2086: 'int string' : redefinition ini_readnwrite.cpp 6
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ini_readnwrite.cpp 7
error C2974: 'boost::property_tree::basic_ptree<std::string,std::string,std::less<Key>>::get' : invalid template argument for 'Type', type expected ini_readnwrite.cpp 10
error C2974: 'boost::property_tree::basic_ptree<std::string,std::string,std::less<Key>>::get' : invalid template argument for 'Ch', type expected ini_readnwrite.cpp 10
error C2146: syntax error : missing ';' before identifier 'value' ini_readnwrite.cpp 10
error C2065: 'value' : undeclared identifier ini_readnwrite.cpp 10
error C2065: 'value' : undeclared identifier ini_readnwrite.cpp 11
IntelliSense: identifier "string" is undefined INI.h 9
IntelliSense: identifier "string" is undefined INI.h 9
IntelliSense: identifier "string" is undefined INI.h 9
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ini.h 9
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ini.h 9
error C2146: syntax error : missing ';' before identifier 'INIreader' ini.h 9
error C2146: syntax error : missing ';' before identifier 'INIreader' ini.h 9
error C2143: syntax error : missing ',' before '&' ini.h 9
error C2143: syntax error : missing ',' before '&' ini.h 9
Thanks.
You need to use the fully qualified name when you attempt to use std::string in your header file:
std::string INIreader(const std::string&, const std::string&);
And do the same thing in INI_readnwrite.cpp, or add a "using" directive like you did in the other .cpp file:
using boost::property_tree::ptree;
using namespace std;
I keep receiving a long string of errors when I try to declare a vector in the header. I've looked around for awhile, but can't find a solution.
Here are the errors:
1>Compiling... 1>game.cpp 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2143:
syntax error : missing ';' before '<'
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';' 1>main.cpp
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax
error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';' 1>input.cpp
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2143: syntax
error : missing ';' before '<' 1>c:\users\legacyblade\documents\visual
studio 2008\projects\fourswords\fourswords\input.h(38) : error C2071:
'input::vector' : illegal storage class
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\legacyblade\documents\visual studio
2008\projects\fourswords\fourswords\input.h(38) : error C2238:
unexpected token(s) preceding ';'
Here is the source code:
#include <vector>
#include <SFML/Graphics.hpp>
#ifndef _input_h
#define _input_h
class input
{
public:
input();
void update();
//----input keys----//
// Directions
bool upPress;
bool downPress;
bool leftPress;
bool rightPress;
// Actions
bool aPress;
bool bPress;
bool jumpPress;
bool shieldPress;
// Menu
bool startPress;
bool screenshotPress;
bool fullscreenPress;
//------------------//
private:
extern vector<sf::Keyboard::Key> keyBindings;
};
#endif
It gives me the same error with and without extern, and even if I change the type of thing inside the vector (even int).
Thank you so much for reading. It would be great if anyone could help. I need vectors to do what I'm wanting to do. Don't know why it's giving me such trouble. Any other type of variable in the same spot DOES NOT cause the error. Only vectors.
Just to add to what's been said, you need the namespace in the declaration because we usually don't want to bloat up header files with "using namespace std". So if you've seen vectors used elsewhere without std:: in front of it, the namespace was probably declared elsewhere.
You need to use the namespace for vector. Prefix vector with std::.
Also, extern on a class member semantically doesn't make any sense. Remove it.
std::vector<sf::Keyboard::Key> keyBindings;
extern vector<sf::Keyboard::Key> keyBindings;
should be
std::vector<sf::Keyboard::Key> keyBindings;
I have some errors in my header file, which I don't know how to fix because I am fairly new to C++.
Here is the code of the header file:
#pragma once
typedef unsigned int uint;
class DCEncryption
{
public:
static char* manageData(char*, char*, uint);
private:
static int max(int, int);
static uint leftRotate(uint, int);
};
And here are the errors:
- dcencryption.h(12): error C2062: type 'int' unexpected
- dcencryption.h(12): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
- dcencryption.h(12): error C2760: syntax error : expected '{' not ';'
- dcencryption.h(13): error C2144: syntax error : 'uint' should be preceded by '}'
- dcencryption.h(13): error C2143: syntax error : missing ')' before ';'
- dcencryption.h(13): error C2059: syntax error : ')'
- dcencryption.h(13): error C2143: syntax error : missing ';' before ')'
- dcencryption.h(13): error C2238: unexpected token(s) preceding ';'
You are probably on Windows and you have included windef.h directly or indirectly (through windows.h, maybe) from your main .cpp file before including the shown file.
It so happens that max is a macro defined in windef.h that does not expand nicely in your context.
This can quite easily happen on some other platforms as well.