| References | Casting | Arrays | Import | instanceof | Package | Synchronization | Throwable | finally | Dangerous | Stack | String |
How to import Class defintions in your source file.
In java a single statement can 'import' a class or a package:
import acdk.util.*; // import all classes from acdk.util
import acdk.net.ServerSocket; // import single class
class Dummy
{
static void foo()
{
ServerSocket server = new ServerSocket(1234);
}
}
|
If you use the class with explicit namespace you even doesn't
need the import statement in Java.
class Dummy
{
static void foo()
{
java.net.ServerSocket server = new java.net.ServerSocket(1234);
}
}
|
In C++ it is not so simple. You have to include the correct headers,
to use the namespace and to link the needed libraries.
In acdk you use:
#include <acdk.h>
#include <acdk/net/SocketServer.h>
|
to include the headers for the declaration of classes.
You can refer to the classes with their full qualified class name:
acdk::net::RServerSocket server = new acdk::io::ServerSocket(1234);
|
You can can 'import' the complete namespace:
using namespace acdk::net;
|
to refer to classes in package/namespace acdk::net with their short form,
often not recommented. But you can use the macro USING_CLASS
USING_CLASS(::acdk::net::, ServerSocket);
// this 'uses' ::acdk::net::ServerSocket, ::acdk::net::RServerSocket,
// ::acdk::net::ServerSocketArray and ::acdk::net::RServerSocketArray
|
|