POV-Ray : Newsgroups : povray.off-topic : C++ question... Server Time
5 Sep 2024 19:24:41 EDT (-0400)
  C++ question... (Message 1 to 10 of 10)  
From: Darren New
Subject: C++ question...
Date: 12 Jun 2009 14:22:18
Message: <4a329cda$1@news.povray.org>
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

From: Fredrik Eriksson
Subject: Re: C++ question...
Date: 12 Jun 2009 14:50:58
Message: <op.uvfda8sa7bxctx@e6600>
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

From: Darren New
Subject: Re: C++ question...
Date: 12 Jun 2009 15:29:23
Message: <4a32ac93$1@news.povray.org>
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

From: Warp
Subject: Re: C++ question...
Date: 13 Jun 2009 13:46:31
Message: <4a33e5f6@news.povray.org>
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

From: Warp
Subject: Re: C++ question...
Date: 13 Jun 2009 13:47:21
Message: <4a33e629@news.povray.org>
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

From: Darren New
Subject: Re: C++ question...
Date: 13 Jun 2009 14:15:12
Message: <4a33ecb0$1@news.povray.org>
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

From: Darren New
Subject: Re: C++ question...
Date: 13 Jun 2009 14:16:53
Message: <4a33ed15$1@news.povray.org>
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

From: JRG
Subject: Re: C++ question...
Date: 14 Jun 2009 13:29:57
Message: <4a353395$1@news.povray.org>
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

From: Darren New
Subject: Re: C++ question...
Date: 14 Jun 2009 13:35:30
Message: <4a3534e2$1@news.povray.org>
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

From: Nicolas Alvarez
Subject: Re: C++ question...
Date: 17 Jun 2009 17:27:26
Message: <4a395fbd$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.