Re: Programming questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 10 March 2004 17:25, Nathan Toone wrote:

> 	First question:  Are most KDE applications written in C or C++?

C++

> 	Second question: What is the difference? (if there is any)

C++ is a language with very similar syntax to C and in large parts code can be 
used interchangeably.
C++ supports object oriented programming and some other very nice things like 
templates (which the newest Java version tries to copy by it Generics)

> 	Third question:  Would you reccommend using the Java Bindings in
> kdebindings to write applications (this would work for new applications,
> just not to change existing applications)?  Or is this not a reccommended
> way of developing applications?

You could write new applications but not change C++ applications.
But using the Qt and KDE bindings for Java gets you close to the workings of 
their C++ origins, so it might be possible to change C++ code after learning 
some C++ basics.
If you are interested in KDE Java development, there is a kde-java mailinglist 
IIRC.

> going the other way...and I know there have to be similarities.  For
> example, in java you say new Object(), or whatever, and in C++ you do
> something wierd (from looking at the code) like Object::Instance~($qstring,

No, in C++ it is
new ClassName()
as well.

> Basically, I'm looking for the C++ equivalents of java's import,
> constructors, method declaration and calls, etc.  Since I think in java,
> I'd like to use it as a jumping off point.

Imports are done by two things.
One is the #include statement, which makes a declaration available to the 
compiler and one is a linker directive to make the implementation known to 
the linker.

Usually you only have to care about the #include at the beginning, because you 
will mostly use classes from the libs commonly linked by the build framework.

Constructors basically work the same as in Java, a difference is that you have 
to use the name of the base class instead of super() if you want to use a 
specific version of the base class's constructors because a C++ class can 
have more than one base class

Methods declarations are similar as well.

In C++ you can put the implementation outseide the class declaration (usually 
in a separate file) or inline like in Java.

Example:
Java
public class Test
{
    public Test() {
        m_number = 0;
    }

    public Test(int n) {
        m_number = n;
    }

    public int number() {
        return m_number;
    }

    private int m_number;
}

C++
class Test
{
public:
    Test() {
        m_number = 0;
    }

    Test(int n) {
        m_number = n;
    }

    int number() {
        return m_number;
    }

private:
    int m_number;

};

If the implementation were not inline it would look like this

class Test
{
public:
    Test();
    Test(int n);

    int number();

private:
    int m_number;

};

Test::Test()
{
    m_number = 0;
}

Test::Test(int n)
{
    m_number = n;
}

int Test::number()
{
    return m_number;
}


Cheers,
Kevin

-- 
Kevin Krammer <kevin.krammer@xxxxxx>
Qt/KDE Developer, Debian User
www.mrunix.de - Unix/Linux programming forum
www.qtforum.org - Qt programming forum

Attachment: pgp00150.pgp
Description: signature

___________________________________________________
.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.

[Index of Archives]     [Trinity (TDE) Desktop Users]     [Fedora KDE]     [Fedora Desktop]     [Linux Kernel]     [Gimp]     [GIMP for Windows]     [Gnome]     [Yosemite Hiking]
  Powered by Linux