Can't declare C++ vector in xcode ios project - c++

I'm trying to use a vector in a C++ class with xcode but it's giving me errors. The file has the .mm extension that is required for C++ files.
This is my code:
class Synth{
private:
int bpm;
std::vector<Note> notesList;
public:
};
It's giving me these two errors:
error: Semantic Issue: Use of undeclared identifier 'std'
error: Parse Issue: Expected member name or ';' after declaration specifiers
I also tried with using namespace std; on top but that made no difference.
Any ideas what could be causing this?

Yes, you need to include the header:
#include <vector>
Don't use using namespace std in a header file, rather keep your code as it is, with the explicit qualifier: std::vector.

Related

Policy data structure on my compiler is not working

I want to use a policy based data structure but my compiler keeps on giving me errors.
Here is what im using in my code:
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
Here are the error messages I recieve:
fatal error:
'ext/typelist.h' file not found
#include <ext/typelist.h>
and
error: function-like macro
'__GLIBC_PREREQ' is not defined
#if __GLIBC_PREREQ(2,15) && defined(_GNU_SOURCE)
I've tried replacing the files over and over again but it keeps on telling me to continuously add new files that my computer does not have. I am using VS Code on a mac. Thank you.
The macro __GLIBC_PREREQ is defined in <cstdlib> , it is not to be guaranteed to be included by default. It looks like you had omitted some vital header or the implementations of those headers don't include <cstdlib>
PBDS requirec gcc, saying that you use VSCode IDE doesn't tell what compiler you're using.

C++ Xcode Library - Undeclared math.h features

I have recently attempted to switch my C++ project's target from an executable to a dynamic library (.dylib), and as soon as I rebuilt with the new target, I get a few errors saying that some defines and declarations in math.h are undeclared, such as M_PI and the sqrt() function.
The error message is as follows: error: use of undeclared identifier 'M_PI', and error: use of undeclared identifier 'sqrt'
This only occurs when I am building my project as a library, and I cannot figure out why it is doing this.
If anyone can help me out on this, it would be much appreciated!
Edit:
Also, if I try to change my include to #include <cmath>, I get more errors, such as: No member named 'signbit' in the global namespace.
Make sure #include <cmath> is at the top of the code, above int main(). I had the same problem. moving the #include <cmath> below <iostream> and above int main() solved the problem for me.

There are unresolved includes inside <iostream>

I just tried to compile my C++ code and an error appears when I try to do so.
The error appears on line 9
Here are the versions of the gcc and g++ and such
Any help would be appreciated.
Edit:
I am also including Movie.h:
And also Movie.cpp:
https://puu.sh/vb53G/9e9abd1832.png (I was not able to include more than 3 images due to restrictions)
Firstly, in your Movie.h file, you have not included the string header file correctly. It should be:
#include <string> // without the .h extension
error: 'string' does not name a type
Secondly, you have forgotten to add the closing parenthesis of the constructor function of class "Movie". I am assuming that you have added this now, after the edit
As for the marking done by your compiler, you may find the following StackOverflow post helpful:
StackOverflow Post: Unresolved inclusion iostream.
The link is for the Eclipse IDE, but you can find a similar solution for your own IDE (I cannot tell which one you have).
The line under the #include is just a warning (I'm not sure why).
However, the errors are from the "Movie" class:
1. add "using namespace std" on the top of this class.
2. close the parenthesis on the constructor of 'Movie'.
The error messages are fairly clear:
'string' does not name a type
That is, the compiler is unaware of the type string because either:
you have not #include <string> in Movie.h
or you have, but have not brought it into your namespace with a using namespace std;
although why not just refer to it as std::string?
You are missing
#include <string>

Why can't my project find "function" in namespace std?

I have the following code:
#interface Model ()
{
//...
std::function<bool(CGFloat, CGFloat)> greaterThan;
std::function<bool(CGFloat, CGFloat)> lesserThan;
//...
}
#end
Everything worked fine in my original project.
I just created a new project, and dragged and dropped the files between the two, and in the new project I have the following errors for the above two lines:
No type named 'function' in namespace 'std'
I don't know what the problem is - The files are .mm , why can't it find function in the names space std ?
Add #include <functional> to the top of your code.
Also remember to use -std=c++0x (or equivalent) in your compiler parameters; this will enable C++11 standard which is required for std::function.

Namespace compilation issues

I am new to working in Visual Studio (am using version 2005). I am running into a problem with namespaces that I am not able to figure out.
I am trying to create a static library which I will link to an Application later.
So, I have a XXX.h file with the following code
#ifndef _XXX_X_H
#define _XXX_X_H
namespace LLL_NWK
{
void lllInit();
}
#endif
I include XXX.h in XXX.c and the code looks like
#include "XXX.h"
using namespace LLL_NWK;
void lllInit()
{
}
However, when I build the Library I encounter the following errors
error C2061: syntax error : identifier 'LLL_NWK'
error C2059: syntax error : ';'
error C2449: found '{' at file scope (missing function header?)
error C2059: syntax error : '}'
I am unable to figure out the cause of this error. Would appreciate some help and pointers.
First, using namespace LLL_NWK is not appropriate here. You are declaring and defining a function void lllInit() outside of namespace LLL_NWK. You need to place the definition inside of the namespace, which can be done like this:
void LLL_NWK::lllInit()
{
}
or like this:
namespace LLL_NWK
{
void lllInit()
{
}
}
Second, make sure you compile the code as C++.
That code is not supported by the C compiler - makes sure to rename the filename to .cpp instead .c. In this case, namespace is not supported. See this post: Namespaces in C