?
Solved

"too many initializers"

Posted on 2008-11-11
4
Medium Priority
?
1,229 Views
Last Modified: 2013-12-14
Hello,

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
        (
          page,
          0.00,
          0.00
        )
        ;// 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_EXPORT(HPDF_STATUS)
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
0
Comment
Question by:Sonja_M
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:obrienslalom
obrienslalom earned 804 total points
ID: 22936496
Seems like the function returns a HPDF_STATUS?
Do you want something like:
HPDF_STATUS status = HPDF_Page_MoveTextPos(...) ?
0
 

Author Comment

by:Sonja_M
ID: 22940808
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
0
 
LVL 3

Accepted Solution

by:
Melange earned 1196 total points
ID: 22942749
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?
0
 

Author Comment

by:Sonja_M
ID: 22945642
Hello,

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.

Sonja
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question