Using Qt in Linux, they speak different C++

In a Linux programming environment
this is part of what the "'Hello World' on a GUI" example app
generated.
Another example of Qt redefining the C++ language?
When does a structure contain virtual functions??
Shouldn't it contain just data types?

// qucom_p.h

struct Q_EXPORT QUBuffer
{
virtual long read( char *data, ulong maxlen ) = 0;
virtual long write( const char *data, ulong len ) = 0;
};
[472 byte] By [Albatross] at [2007-11-19 18:30:23]
# 1 Re: Using Qt in Linux, they speak different C++
When does a structure contain virtual functions??
A struct is a class but with public access as the default.

Shouldn't it contain just data types?
Ever seen function objects with no member variables declared with struct?
laserlight at 2007-11-9 0:55:47 >
# 2 Re: Using Qt in Linux, they speak different C++
Ever seen function objects with no member variables declared with struct?

No, never have.
I have tried to implements such syntax in a Windows MFC app
and the compiler won't accept it. Why?

here's what I had :

// Abc.cpp: Implementierungsdatei
//

#include "stdafx.h"
#include "DumbTest.h"
#include "Abc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Abc

!!!!!! here the compiler did not accept this :

struct Abuffer
{
virtual int f1(int n1) = 0;
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Abc::Abc()
{
}

Abc::~Abc()
{
}
Albatross at 2007-11-9 0:56:57 >
# 3 Re: Using Qt in Linux, they speak different C++
I have tried to implements such syntax in a Windows MFC app
and the compiler won't accept it. Why?
For one thing, your struct declaration doesnt have a terminating semi-colon.
laserlight at 2007-11-9 0:57:54 >
# 4 Re: Using Qt in Linux, they speak different C++
Right you are!!!
There was no terminating semi-colon. It compiles in MFC now.
Okay I accept it.

But I can't see the use of it. Why not make a class?

The use of virtual functions is to make a virtual class, isn't it? It makes redefinition/implementation mandatory when inheriting.

But who inherits structures?
Albatross at 2007-11-9 0:58:59 >
# 5 Re: Using Qt in Linux, they speak different C++
But I can't see the use of it. Why not make a class?
I suppose it doesnt really matter either way. In this case, you could also write:
class Abuffer
{
public:
virtual int f1(int n1) = 0;
};
But using the keyword struct instead of class means you can leave the public label out without changing the meaning of the declaration.
laserlight at 2007-11-9 0:59:53 >
# 6 Re: Using Qt in Linux, they speak different C++
But I can't see the use of it. Why not make a class?

It saves a typing the "public:" keyword for our fingers, although, I admit that it is not very useful.

The use of virtual functions is to make a virtual class, isn't it? It makes redefinition/implementation mandatory when inheriting.

Little correction: pure virtual functions must be implemented by concrete derived classes, or by another derived class of the base class, higher in the hierarchy.

And, of course, non-pure virtual functions are meant to be overriden.

But who inherits structures?

Any class or struct can inherit a struct.

For C++, there is no difference between a class and a struct except that struct default access for members and inheritance is public, instead of private for classes.
SuperKoko at 2007-11-9 1:00:54 >