and I am trying to now do a Breadth First Order for files but, when I implement this template class to use a Queue I get this errors?, any idea where this might be?, also I do not understand the way the line number where the error is, is specified (i.e myprogram.c:23:10) no idea where that is
program.c:11:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
program.c:22:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
program.c:33:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
program.c: In function ‘display_info’:
program.c:49:3: error: ‘q_type’ undeclared (first use in this function)
program.c:49:3: note: each undeclared identifier is reported only once for each function it appears in
program.c:49:10: error: ‘string’ undeclared (first use in this function)
program.c:49:18: error: ‘bfFilesQueue’ undeclared (first use in this function)
program.c:50:18: error: ‘bfDirsQueue’ undeclared (first use in this function)
Now the Queue class was taken from here, and I want to use it with strings , basically a file path
http://www.java2s.com/Code/Cpp/Generic/Createagenericqueue.htm
So my questions are, because i don't expect you to debug this for me.. but want to know the following:
I tried to declare the queue at the top after the #include's so that i have have access to them globally. It seems like it does not like it because i am trying to use it from the display_info function. How can I declare this so that I have access to those Queues from anywhere?
I dont understand how to check in which line it is telling about the error (i.e. :12:10), i took that Template class from the link i posted.. not sure why would it throw an error.. How can I know the line number based on those weird numbers?
So the code and errors are just informational so that you may answer those two questions with enough information.. any help will be much appreciated.
Thank you
#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#define SIZE 100
template <class Qtype> class q_type {
Qtype queue[SIZE];
int head, tail;
public:
q_type() {
head = tail = 0;
}
void q(Qtype num);
Qtype deq();
};
template <class Qtype> void q_type<Qtype>::q(Qtype num)
{
if(tail+1==head || (tail+1==SIZE && !head)) {
cout << "Queue is full.\n";
return;
}
tail++;
if(tail==SIZE)
tail = 0; // cycle around
queue[tail] = num;
}
template <class Qtype> Qtype q_type<Qtype>::deq()
{
if(head == tail) {
cout << "Queue is empty.\n";
return 0;
}
head++;
if(head==SIZE)
head = 0;
return queue[head];
}
q_type<string> bfFilesQueue;
q_type<string> bfDirsQueue;
static int display_info(const char *fpath, const struct stat *sb,
int tflag, struct FTW *ftwbuf)
{
//Check the type of Flag (i.e File or Directory)
switch(tflag)
{
case FTW_D:
case FTW_F:
bfFilesQueue.q(fpath);
break;
case FTW_DP:
bfDirsQueue.q(fpath);
break;
}
return 0; /* Continue */
}
program.c:11:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘<’ token
That sounds like you're compiling the C++ source code as C.
A simple fix can then be to rename the file as program.cpp.
Cheers & hth.,
You declare
q_type<string> bfFilesQueue;
q_type<string> bfDirsQueue;
before you actually declare q_type. Try putting these lines after the class
Related
I have some code working in OpenGL and now I would like to use ImGui to make a GUI for my application.
When I tried to copy a one line code of ImGui to my project ImGui::CreateContext(); by including some of the header files of ImGui, it lasted by a hundred errors (due maybe to linking).
I'm working with Ubuntu 18 and I use a Makefile to compile the whole project
Some of the errors that I got when including imgui.h:
imgui/imgui.h:153:39: error: unknown type name ‘ImGuiInputTextCallbackData’; did you mean ‘ImGuiInputTextFlags’?
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
^~~~~~~~~~~~~~~~~~~~~~~~~~
ImGuiInputTextFlags
imgui/imgui.h:154:35: error: unknown type name ‘ImGuiSizeCallbackData’
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
^~~~~~~~~~~~~~~~~~~~~
imgui/imgui.h:179:5: error: expected specifier-qualifier-list before ‘ImVec2’
ImVec2() { x = y = 0.0f; }
^~~~~~
imgui/imgui.h:192:5: error: expected specifier-qualifier-list before ‘ImVec4’
ImVec4() { x = y = z = w = 0.0f; }
^~~~~~
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
isspace
imgui/imgui.h:205:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
{
^
In file included from window.c:23:0:
imgui/imgui.h:1200:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘new’
inline void* operator new(size_t, ImNewDummy, void* ptr) { return ptr; }
^~~
imgui/imgui.h:1201:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete’
inline void operator delete(void*, ImNewDummy, void*) {} // This is only required so we can use the symmetrical new()
^~~~~~
imgui/imgui.h:1206:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T> void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p); } }
^
imgui/imgui.h:1217:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
template<typename T>
^
imgui/imgui.h:1280:5: error: unknown type name ‘ImVec2’
ImVec2 WindowPadding; // Padding within a window.
When I run some examples that are provided, they work perfectly. However, when trying to merge my project with a single line of code of imgui, it ends up with the errors shown above.
Looking at the kind of errors you are getting, it seems to me that you are trying to compile your program with a C compiler. However, ImGui is written in C++.
For, example:
imgui/imgui.h:204:1: error: unknown type name ‘namespace’; did you mean ‘isspace’?
namespace ImGui
^~~~~~~~~
namespace is a C++ reserved keyword and your compiler doesn't seem to recognize it as such.
Since you mentioned that you are using MakeFile, try to find in that file what compiler you are using. If it says gcc, replace it by g++. If it's using clang, replace it by clang++.
#ifndef UNO_ACTION_
#define UNO_ACTION_
namespace Uno
{
namespace Game
{
class Game;
}
} // namespace
namespace Uno
{
namespace Action
{
using ::Uno::Game::Game;
class Action
{
public:
virtual bool isDisposeable() = 0;
virtual void takeAction(Game* game) = 0;
virtual ~Action() {}
};
}
}
#endif
I compile these code on ubuntu 12.04 and it returns to set of error:
action.h:4:1: error: unknown type name ‘namespace’
action.h:4:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
action.h:8:1: error: unknown type name ‘namespace’
action.h:8:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
How do I solve these errors?
It sounds like you're trying to compile your C++ code with a C compiler. Try using g++ instead of gcc and giving your file a C++ extension such as .cpp (rather than .c).
Had this issue with YCM and clang. Turns out, the missing flag was "-x", "c++".
From the official clang documentation:
-x <language> : Treat subsequent input files as having type language.
I had a similar issue and found this question but the solutions don't match mine completely, so I'm adding mine here.
In my case, I was including a header file in .cpp files and .c files.
The solution was to split off the namespace part of the header since that was obviously only needed in the .cpp files.
Hello there I am iplementingh a binary tree based on an underlying array.
My project is comprises a set of c++ files and the makefile for generating the compilation.
I am using g++ provided with DEV-C++ 4.9.9.2.
Upon launching compilation I get the following two set of errors.
AlberoBinariov.h: In member function bool AlberoBinariov<T>::figlioSinistroVuoto(typename Alberoa<T, int>::posizioneNodo)':
AlberoBinariov.h:198: error: expected)' before ';' token
AlberoBinariov.h:198: error: expected primary-expression before ')' token
AlberoBinariov.h:198: error: expected `;' before ')' token
AlberoBinariov.h: In member function bool AlberoBinariov<T>::figlioDestroVuoto(typename Alberoa<T, int>::posizioneNodo)':
AlberoBinariov.h:204: error: expected)' before ';' token
AlberoBinariov.h:204: error: expected )' before ';' token
AlberoBinariov.h:204: error: expected primary-expression before ')' token
AlberoBinariov.h:204: error: expected;' before ')' token
Interested portions of code are provided below:
template <class T>
bool AlberoBinariov<T>::figlioSinistroVuoto(posizioneNodo p)
{
return (figlioSinistro(p)==(posizioneNodo)P_NULL); //line 198
}
template <class T>
bool AlberoBinariov<T>::figlioDestroVuoto(posizioneNodo p)
{
return (figlioDestro(p)==((posizioneNodo)P_NULL)); //line 204
}
also for your convenince I have included the full source code at the link below.
https://filetea.me/t1sc3e60
Can you please let me know? thanks you in advance for your time. I look forward to hear from you.
Kind regards,
Gerald
PS: P_NULL is a NULL pointer constant declared in the Constants.h file.
You have 3 individual right parenthesis without their corresponding left parenthesis:
return (figlioDestro(p) == ((posizioneNodo)P_NULL)) /* -> */ )));
Change it to this:
return (figlioDestro(p) == ( (posizioneNodo)P_NULL ));
I am getting this error during compile time (g++ 4.4.6):
main.cpp: In function ‘int main()’:
main.cpp:27: error: expected initializer before ‘:’ token
main.cpp:33: error: expected primary-expression before ‘for’
main.cpp:33: error: expected ‘;’ before ‘for’
main.cpp:33: error: expected primary-expression before ‘for’
main.cpp:33: error: expected ‘)’ before ‘for’
main.cpp:33: error: expected initializer before ‘:’ token
main.cpp:36: error: could not convert ‘((list != 0u) ? (list->SortedList::~SortedList(), operator delete(((void*)list))) : 0)’ to ‘bool’
main.cpp:37: error: expected primary-expression before ‘return’
main.cpp:37: error: expected ‘)’ before ‘return’
My code is as follows:
#include <iostream>
#include "Student.h"
#include "SortedList.h"
using namespace std;
int main() {
SortedList *list = new SortedList();
Student create[100];
int num = 100000;
for (Student &x : create) { // <--Line 27
x = new Student(num);
num += 10;
}
for (Student &x : create)
list->insert(&x);
delete list;
return 0;
}
Anybody who possibly knows the source of the error would be of great help. Also, Student and SortedList are objects which are declared in their .h files.
According to this page on GCC's website, range-based for is only available in g++ 4.6 and up, so you'll have to convert your code to a normal for loop or use std::for_each or something, or upgrade your compiler.
// File test.cpp
#include <my_global.h>
#include <algorithm>
int main()
{
return 0;
}
Compiled with: g++ -c -I /usr/local/mysql/include/mysql/ test.cpp, where /usr/local/mysql is the mysql install directory.Then the compiler report the following errors:
In file included from /usr/include/c++/4.4/algorithm:61,
from test.cpp:3:
/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, but takes just 2
/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, but takes just 2
In file included from /usr/include/c++/4.4/bits/stl_algo.h:61,
from /usr/include/c++/4.4/algorithm:62,
from test.cpp:3:
/usr/include/c++/4.4/bits/algorithmfwd.h:353:41: error: macro "max" passed 3 arguments, but takes just 2
/usr/include/c++/4.4/bits/algorithmfwd.h:364:41: error: macro "min" passed 3 arguments, but takes just 2
In file included from /usr/include/c++/4.4/algorithm:61,
from test.cpp:3:
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected unqualified-id before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’ variable
/usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp& std::min’
/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected primary-expression before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected ‘}’ before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:237: error: expected unqualified-id before ‘return’
/usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable
/usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp& max’
/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected primary-expression before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected ‘}’ before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:258: error: expected unqualified-id before ‘return’
/usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token
I think that there's some name conflict between my_global.h and algorithm, so I wrap my_global.h in a namespace:
// File test.cpp
namespace MYSQL_NAMESPACE {
#include <my_global.h>
}
#include <algorithm>
int main()
{
return 0;
}
But it doesn't help, the compiler still report the same errors. Then I change the include order as following:
// File test.cpp
#include <algorithm>
#include <my_global.h>
int main()
{
return 0;
}
Every thing goes well now.
Does Anybody Really Know What The Problem It Is?
TKS!
It seems that the mysql header defines a macro min.
#if !defined(max)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
This has been reported to MySQL as bug 28184. The bug is marked as closed, so try updating to the newest version. According to the bug page it should be fixed in version 5.1.23, version 6.0.4 and newer versions.
Apparently the namespace trick does not work because min/max are macros and the preprocessor does not look at namespace scope.
This might fix the problem:
#include <my_global.h>
#undef min
#undef max
#include <algorithm>
The whole thing looks horrible though :)
It looks like my_global.h defines some name used by algorithm as a preprocessor macro, causing compilation to fail. With the ordering that works, you won't be able to use whatever it is that my_global.h clobbers, but your code will at least compile unless you need that feature. Since preprocessor macros are not namespaced, the namespace wrapping will not help, as you have observed.
Therefore, it sounds like my_global.h is broken, but if everything works just use the include order that works and go with it. That's my preferred include order anyway - standard library headers first, followed by external library headers, followed by internal headers.