|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Isn't it legal to put a class declaration in the same .cpp file where you
define its member functions and the main() that's the only routine that uses it?
When I did that, I got errors about not being able to find the vtable for
the class.
Is #include supposed to work just like a textual include? Is this something
funky with the Qt preprocessing stuff?
--
Darren New, San Diego CA, USA (PST)
Insanity is a small city on the western
border of the State of Mind.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Fri, 12 Jun 2009 20:22:16 +0200, Darren New <dne### [at] sanrrcom> wrote:
> Isn't it legal to put a class declaration in the same .cpp file where
> you define its member functions and the main() that's the only routine
> that uses it?
You can put the entire program in a single file if you want.
> When I did that, I got errors about not being able to find the vtable
> for the class.
Possibly some internal compiler problem (which might be triggered by a
syntactical problem in your code).
> Is #include supposed to work just like a textual include?
Yes.
--
FE
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Fredrik Eriksson wrote:
>> Is #include supposed to work just like a textual include?
> Yes.
OK. I think the problem is that Qt runs the code through a preprocessor for
various reasons, and it was probably not running the .cpp stuff thru, just
the .h stuff.
--
Darren New, San Diego CA, USA (PST)
Insanity is a small city on the western
border of the State of Mind.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> > Is #include supposed to work just like a textual include?
> Yes.
With two minor exceptions:
1) Certain compiler-dependent #pragmas may change the behavior of #include
slightly. The most common one is "#pragma once".
2) __FILE__ will expand to the name of the header file if it appears in
it, rather than the source file where it's #included. Likewise for __LINE__.
Thus if either identifier is used in a header file, its behavior will be
different than if you copy-pasted the contents of the header file to the
source file.
(The exception is if either identifier is used in a preprocessor macro, in
which case they are interpreted only after expanding the macro instantiation.)
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New <dne### [at] sanrrcom> wrote:
> When I did that, I got errors about not being able to find the vtable for
> the class.
A minimal example code would help a lot answering the question.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
>>> Is #include supposed to work just like a textual include?
>
>> Yes.
>
> With two minor exceptions:
Good point, thanks! Neither of which was the problem, which seems to be
specific to Qt, which runs its own preprocessors. But thanks for the
clairifications.
--
Darren New, San Diego CA, USA (PST)
Insanity is a small city on the western
border of the State of Mind.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> When I did that, I got errors about not being able to find the vtable for
>> the class.
>
> A minimal example code would help a lot answering the question.
Yeah. I solved it before I asked the question. I was just trying to figure
out if it was normal C++ stuff or QT stuff. Once I got confirmed that
#include in C++ was essentially the same as in C (modulo leaving off .h), I
went grubbing around QT and figured out there's a macro it only expands in
.H files with the "moc" processor.
--
Darren New, San Diego CA, USA (PST)
Insanity is a small city on the western
border of the State of Mind.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New wrote:
> Isn't it legal to put a class declaration in the same .cpp file where
> you define its member functions and the main() that's the only routine
> that uses it?
>
> When I did that, I got errors about not being able to find the vtable
> for the class.
>
> Is #include supposed to work just like a textual include? Is this
> something funky with the Qt preprocessing stuff?
>
Perfectly legal.
As far as Qt is concerned... are you running moc by yourself?
You known, qmake uses the HEADERS variable to look for Q_OBJECT classes.
If your private class contains that macro, just try and include the
generated .moc directly.
Something like:
source.cpp:
class my_private_implementation
{
Q_OBJECT
/* neat stuff */
};
#include "source.moc"
--
Jonathan.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
JRG wrote:
> As far as Qt is concerned... are you running moc by yourself?
> You known, qmake uses the HEADERS variable to look for Q_OBJECT classes.
I see. No, I'm a Qt newbie. I just worked out this weekend how to compile
something outside of the Qt subdirectories. :-) {To be fair, it's
cross-compiled from a VM to a piece of hardware that doesn't have any
keyboard or mouse, so it's not like it's trivial.}
> If your private class contains that macro, just try and include the
> generated .moc directly.
Cool. It's easy enough to put it in a separate .h file. It just surprised
me. Looking at it, I thought Q_OBJECT was a #define, not some tag for a
separate preprocessor.
You know something else that surprises me? That I can screw up the
compilation enough to get G++ outputting assembler that the assembler
doesn't understand. I can't imagine why I can invoke G++ with arguments
that, in one execution, would compile C++ to assembly, then pass that
assembly to the assembler for the wrong architecture. Weird.
--
Darren New, San Diego CA, USA (PST)
Insanity is a small city on the western
border of the State of Mind.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Darren New wrote:
> Cool. It's easy enough to put it in a separate .h file. It just surprised
> me. Looking at it, I thought Q_OBJECT was a #define, not some tag for a
> separate preprocessor.
I believe it's both.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |