"too many initializers"


I get the compiler error C2078: too many initializers. Why ? I retyped the source, it does not seem anything like invisible characters causing the bug.

Here is the source extract, with the error located at line 9:
      HPDF_Page_BeginText (page);
      HPDF_Page_SetFontAndSize(page, "Helvetica", 10);
      HPDF_STATUS HPDF_Page_MoveTextPos
        ;// On this line, I get the following compiler error: error C2078: too many initializers
      HPDF_Page_ShowText (page, "Test text");
      HPDF_Page_EndText (page);

and here is the extract from the *.h file:
HPDF_Page_MoveTextPos  (HPDF_Page   page,
                        HPDF_REAL   x,
                        HPDF_REAL   y);
another extract:
typedef  float               HPDF_REAL;

This part of the program is supposed to write some text into a pdf which is being created by the libharu library. To include a jpeg into the pdf already works fine, but to write a title, I failed. I guess the problem is the c++ syntax, and not something around this libharu.

In a demo program, I see function calls such as  "HPDF_Page_MoveTextPos (page, x - 20, y - 25);", so I really cannot see any difference to what I did.

I am sure it is one of those tiny bugs you have no chance to find them after analysing it for too long. So I would apprechiate your fresh look :-)

Best regards, Sonja
Who is Participating?
To expand on obrienslalom's comment, the reason you're getting the "too many initializers" error is that in your statement:

HPDF_STATUS HPDF_Page_MoveTextPos(page, 0.00, 0.00);

you're not calling a function, you're tying to declare a variable of type HPDF_STATUS with the name of HPDF_Page_MoveTextPos and with the parameters (page, 0.00, 0.00) passed to the constructor of HPDF_STATUS. This, obviously, doesn't work and isn't what you intended, hence the error.

If you don't care about the return value, you can simply use:

HPDF_Page_MoveTextPos(page, 0.00, 0.00);

or save the result of the return HPDF_STATUS status = ... etc. (as mentioned above).

As to why you're getting a runtime error, I can only speculate. Perhaps the "page" variable has not been properly set up?
Seems like the function returns a HPDF_STATUS?
Do you want something like:
HPDF_STATUS status = HPDF_Page_MoveTextPos(...) ?
Sonja_MAuthor Commented:
Hello obrienslalom,

thanks for your interesting answer.

here is an extract from the demo program:
  HPDF_Page_BeginText (page);
  HPDF_Page_MoveTextPos (page, 60, height - 105);
  i = 0;
as you see, there is no "status=HPDF_...".

Also, if this would be the problem, I would expect another error message.
I admit the source DOES compile when following your answer. But then I get an error at runtime. Summary: I guess your proposition corrects the bug just on the surface, it is a slalom around the deeper bug.

Any ideas where to continue the search ?

Sonja_MAuthor Commented:

melange wrote:
>If you don't care about the return value, you can simply use:
>HPDF_Page_MoveTextPos(page, 0.00, 0.00);
yes, this is exactly what I wanted to do, but I failed: a bug when using copy-paste, and I was too blind to detect it.

> As to why you're getting a runtime error, I can only speculate. Perhaps the "page" > variable has not been properly set up?
I try to debug that myself, or ask a second question; it is off-topic here.

so thanks to both the slalom master and the mixer who de-mixed my source.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.