/*
Project name: java2cpp
Author: Lucas Henrique
Date (start): 30/11/2013
*/
//In this "framework", you DON'T need use "package". (And you can't)
#include "java.h" /* See one*/
importing java::basics; /*See two*/
int main(int argc, String args[]) /*See three*/
{
System.out.println("Hello World!");
System.out.print("Printing without spaces. ");
System.out.print("Text two, like Java!");
Scanner input = new Scanner("System.in");
}
/* See xxx...
1. The main file root for the Java programmer that DON'T want to use an interpreter. "#include" is an C++ keyword to include function-files. Have sure that the java.h file is in the project directory
2. The "import" keyword is used by C++, so I made this.
importing java;
using basics; is :"use namespace basics from the namespace java". "import java::basics" ESSENTIAL to everything work. There are also others namespaces from namespace java. Use :: operator as . in java, but you dont need to (and you cant) use * to include (they aren't files);
3. The main ONLY return integers. By default, C++ has "argc", and this is the argument count. Example:
Source:
#include "java.h"
using java::basics;
int main(int argc, String args[])
{
System.out.println(argc);
}
String in = "Sytem.in";
On command line:
MyProject.exe argumentone argumenttwo argumentthree blabla helloworld
Return: 6
Logic:
1. EXE name (MyProject.exe)
2. argumentone
3. argumenttwo
4. argumentthree
5. blabla
6. helloworld
Please, see README.htm file for more info.
*/
Since the constructor you build for the class Scanner asks for a parameter of type String, you must provide this type of parameter. Now, if System.in is of type String then it's partly ok. Partly because with the new keyword you actually create a pointer, so the correct line would be:
> do EXACTLY as the way that I want? (Scanner object = new Scanner(System.in))
Yes, but you have to write a bit of code if you want it to work just as a reference in Java would.
(A terrible idea unless it is purely for purposes of learning C++. Why would anyone want to mimic in C++ the constructs of a language which has no notion of value semantics, no notion of const-correctness and no notion of RAII?)
C:\Users\Lucas\Desktop\Projetos\C++\teste.cpp|26|error: no members matching 'NullPointerException::base {aka std::runtime_error}::base' in 'using base = class std::runtime_error {aka class std::runtime_error}'|
C:\Users\Lucas\Desktop\Projetos\C++\teste.cpp|33|error: no members matching 'OutOfMemoryError::base {aka std::runtime_error}::base' in 'using base = class std::runtime_error {aka class std::runtime_error}'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 3 seconds) ===|
:(
You are using an older version of the compiler; one that does not support all C++ language features.
Try this modified code (without type aliases, inherited constructors and defaulted member functions):