I get this error when trying to compile: `error: invalid use of void expression  I get this error at the penultimate line: queueDump(f, q, printToken(f, e)); and I don't understand why. I'm trying to code the function printToken that prints the token pointed by e  void queueDump(FILE *f, Queue *q, void(*dumpfunction)(FILE *f, void *e)) {     fprintf(f, "(%d) --  ", q-&gt;size);     for (InternalQueue *c=q-&gt;head; c != NULL; c = c-&gt;next)         dumpfunction(f, c-&gt;value); }  void printToken(FILE *f, void *e) {     Queue *q;     if (!f) {         printf("Erreur d'ouverture du fichier\n");         exit(1);     }     fprintf(f, "Infix : ");     queueDump(f, q, printToken(f, e));     fclose(f); }
31933
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
8017
I often find myself in a situation where I am facing multiple compilation/linker errors in a C++ project due to some bad design decisions (made by someone else :) ) which lead to circular dependencies between C++ classes in different header files (can happen also in the same file). But fortunately(?) this doesn't happen often enough for me to remember the solution to this problem for the next time it happens again.  So for the purposes of easy recall in the future I am going to post a representative problem and a solution along with it. Better solutions are of-course welcome.     A.h  class B; class A {     int _val;     B *_b; public:      A(int val)         :_val(val)     {     }      void SetB(B *b)     {         _b = b;         _b-&gt;Print(); // COMPILER ERROR: C2027: use of undefined type 'B'     }      void Print()     {         cout&lt;&lt;"Type:A val="&lt;&lt;_val&lt;&lt;endl;     } };       B.h  #include "A.h" class B {     double _val;     A* _a; public:      B(double val)         :_val(val)     {     }      void SetA(A *a)     {         _a = a;         _a-&gt;Print();     }      void Print()     {         cout&lt;&lt;"Type:B val="&lt;&lt;_val&lt;&lt;endl;     } };       main.cpp  #include "B.h" #include &lt;iostream&gt;  int main(int argc, char* argv[]) {     A a(10);     B b(3.14);     a.Print();     a.SetB(&amp;b);     b.Print();     b.SetA(&amp;a);     return 0; }
21871
I am trying to pass a reference to a two-dimensional array to a function in C++. I know the size of both dimensions at compile time. Here is what I have right now:  const int board_width = 80; const int board_height = 80; void do_something(int[board_width][board_height]&amp; array);  //function prototype   But this doesn't work. I get this error from g++:  error: expected ‘,’ or ‘...’ before ‘*’ token   What does this error mean, and how can I fix it?
6108
Why do I get compiler errors with this Java code?  1  public List&lt;? extends Foo&gt; getFoos() 2  { 3    List&lt;? extends Foo&gt; foos = new ArrayList&lt;? extends Foo&gt;(); 4    foos.add(new SubFoo()); 5    return foos; 6  }  Where 'SubFoo' is a concrete class that implements Foo, and Foo is an interface.  Errors I get with this code:   On Line 3: "Cannot instantiate ArrayList&lt;? extends Foo&gt;" On Line 4: "The method add(capture#1-of ? extends Foo) in the type List&lt;capture#1-of ? extends Foo&gt; is not applicable for the arguments (SubFoo)"   Update: Thanks to Jeff C, I can change Line 3 to say "new ArrayList&lt;Foo&gt;();".  But I'm still having the issue with Line 4.
57217
Compiling the following code and got the error of type illegal.  int main() {     // Compilation error - switch expression of type illegal     switch(std::string("raj"))     {     case"sda":     } }   You cannot use string in either switch or case. Why? Is there any solution that works nicely to support logic similar to switch on strings?
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
1377
Is there any good reason that an empty set of round brackets (parentheses) isn't valid for calling the default constructor in C++?  MyObject  object;  // ok - default ctor MyObject  object(blah); // ok  MyObject  object();  // error   I seem to type "()" automatically everytime. Is there a good reason this isn't allowed?
7075
I have a function which parses one string into two strings.  In C# I would declare it like this:  void ParseQuery(string toParse, out string search, out string sort) {     ... }   and I'd call it like this:  string searchOutput, sortOutput; ParseQuery(userInput, out searchOutput, out sortOutput);   The current project has to be done in C++/CLI.  I've tried  using System::Runtime::InteropServices;  ...  void ParseQuery(String ^ toParse, [Out] String^ search, [Out] String^ sort) {     ... }   but if I call it like this:  String ^ searchOutput, ^ sortOutput; ParseQuery(userInput, [Out] searchOutput, [Out] sortOutput);   I get a compiler error, and if I call it like this:  String ^ searchOutput, ^ sortOutput; ParseQuery(userInput, searchOutput, sortOutput);   then I get an error at runtime.  How should I declare and call my function?
115381
I'm trying to write this:  \begin{nscenter}         % $G(\psi,\chi) =          \         % \begin{cases}         % \begin{enumerate}[\rm(i)]         % \item q-1 \ se \ \psi=\psi_0 \ e \ \chi=\chi_0 \\         % \item -1 \ se \ \psi=\psi_0 \ e \ \chi \neq \chi_0 \\          % \item 0 \ se \psi \neq \psi_0 \ e \ \chi=\chi_0 \\          $ \item Se \ \chi \neq \chi_0 \ e \ \psi \neq \psi_0 \Rightarrow  $ |G(\psi,\chi)|=\sqrt{q}          $ \end{enumerate}          $ \end{cases}$      %\end{nscenter}   But the compiler of the error and I do not know what to do to remove the error
1838
Is there any way to achieve function overloading in C? I am looking at simple functions to be overloaded like    foo (int a)   foo (char b)   foo (float c , int d)   I think there is no straight forward way; I'm looking for workarounds if any exist.
97610
First of all I have to admit that my programming skills are pretty limited and I took over a (really small) existing C++ OOP project where I try to push my own stuff in. Unfortunately I'm experiencing a problem which goes beyond my knowledge and I hope to find some help here. I'm working with a third party library (which cannot be changed) for grabbing images from a camera and will use some placeholder names here.   The third party library has a function "ThirdPartyGrab" to start a continuous live grab and takes a pointer to a function which will be called every time a new frame arrives. So in a normal C application it goes like this:  ThirdPartyGrab (HookFunction);   "HookFunction" needs to be declared as:   long _stdcall HookFunction (long, long, void*);   or "BUF_HOOK_FUNCTION_PTR" which is declared as  typedef long (_stdcall *HOOK_FUNCTION_PTR) (long, long, void*);   Now I have a C++ application and a class "MyFrameGrabber" which should encapsulate everything I do. So I put in the hook function as a private member like this:  long _stdcall HookFunction (long, long, void*);   Also there is a public void function "StartGrab" in my class which should start the Grab. Inside I try to call:  ThirdPartyGrab (..., HookFunction, ...);   which (not surprisingly) fails. It says that the function call to MyFrameGrabber::HookFunction misses the argument list and I should try to use &amp;MyFrameGrabber::HookFunction to create a pointer instead. However passing "&amp;MyFrameGrabber::HookFunction" instead results in another error that this cannot be converted to BUF_HOOK_FUNCTION_PTR.   After reading through the  I think I understand the problem but can't make up a solution. I tried to make the hook function static but this also results in a conversion error. I also thought of putting the hook function outside of the class but I need to use class functions inside the hook function. Is there another way or do I need to change my whole concept?   EDIT 14.01.08: I tested the singleton workaround since I cannot change the third party library and the void pointer is only for data that is used inside the hook function. Unfortunately it didn't worked out of the box like I hoped.... I don't know if the static function needs to be in a separate class so I put it in my "MyFrameGrabber" class:  static MyFrameGrabber&amp; instance() {         static MyFrameGrabber _instance;         return _instance; } long Hook(long, long, void*); // Implementation is in a separate cpp file   In my cpp file I have the call_hook function:  long MFTYPE call_hook(long x, MIL_ID y, void MPTYPE *z) {     return MyFrameGrabber::instance().Hook(x,y,z); } void MyFrameGrabber::grab () {     ThirdPartyGrab(..., call_hook, ...); }   But this gives me an error in static MatroxFrameGrabber _instance; that no matching standard constructor is found. That's correct because my MyFrameGrabber constructor looks like this:  MyFrameGrabber (void* x,                 const std::string &amp;y, int z,                 std::string &amp;zz);   I tried to put in an empty constructor MyFrameGrabber(); but this results in a linker error. Should I pass empty parameters to the MyFrameGrabber constructor in the singleton? Or do I need to have a separate Hook Class and if yes how could I access MyFrameGrabber functions? Thanks in advance.   SECOND EDIT 15.01.08: I applied the changes and it compiles and links now. Unfortunately I cannot test this at runtime yet because it's a DLL and I have no Debug Caller Exe yet and there are other problems during initialization etc. I will mark the post as answer because I'm sure this is the right way to do this.
85376
On Visual Studio 2005 C++ compiler, I get the following warning when my code uses the fopen and such calls.  1&gt;foo.cpp(5) : warning C4996: 'fopen' was declared deprecated 1&gt;        c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen' 1&gt;        Message: 'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'   How do I prevent this?
9770
I'm sure you all know the behaviour I mean - code such as:  Thread thread = new Thread(); int activeCount = thread.activeCount();   provokes a compiler warning.  Why isn't it an error?  EDIT:  To be clear: question has nothing to do with Threads.  I realise Thread examples are often given when discussing this because of the potential to really mess things up with them.  But really the problem is that such usage is always nonsense and you can't (competently) write such a call and mean it.  Any example of this type of method call would be barmy.  Here's another:  String hello = "hello"; String number123AsString = hello.valueOf(123);   Which makes it look as if each String instance comes with a "String valueOf(int i)" method.
11502
How should I use array of function pointers in C?  How can I initialize them?
16584
would report a violation for:  ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;();   The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead".  The following line would correct the violation:  List&lt;Object&gt; list = new ArrayList&lt;Object&gt;();   Why should the latter with List be used instead of ArrayList?
82347
Okay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' of this in a scenario where it would actually affect the program?  Classic Example:  int i = 0; foo(i++, i++);   Note: I'm not looking for someone to tell me that the order of evaluation can't be relied on, I'm well aware of that. I'm only interested in whether any compilers actually do evaluate out of a left-to-right order because my guess would be that if they did lots of poorly written code would break (rightly so, but they would still probably complain).
54781
I have a couple of LaTeX files with the same problem. If I produce an error, fix it, and then try to compile a pdf, I get the following error.  )Runaway argument? {{ ! File ended while scanning use of \@newl@ablel. &lt;inserted text&gt;                 \par l.90 \begin{document}   If I then click on the console or trash my .aux file, it compiles fine. Any thoughts on what is going on and how to prevent this annoying extra step?