I'm used to program in Java and I started to program in c++. Now in java if you have 2 classes (Class1.java and Class2.java) you could say in Class1: mClass2 = new Class2();
How do you do that in C++, I tried the following:
1 2 3 4 5 6
Class2 *mCLass2;
and
Class2 mClass2;
But nothing works. The classes are doing nothing yet, I just want to make an instance of an external class. HOw do I do this in c++
1>CLass1.cpp(3): error C2146: syntax error : missing ';' before identifier 'mClass2'
1>Class1.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>Class1.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Then why not tell us that upfront? If you want people to help, it's in your interest to provide us with as much information as possible.
Without seeing your code, it's impossible to be sure what's causing the problem, but my guess would be that you've forgotten to include the definition of Class2 in the code that's trying to instantiate an object of the class.
you need to include the second file
In java you'd have to include a package if Class2 were in a different package, in c++ there are no packages and so you need to include the header files you need.
1 2 3 4 5 6
#ifndef CLASS2_H
#define CLASS2_H
class Class2 {};
#endif // CLASS2_H
It sounds like you really need to go back to the very basics of C++, and get some understanding of the rudiments of the language. In order for the compiler to understand what "Class2" means, you have to include the definition of that type. The conventional way to do this is as Gamer2015 has shown - by putting the class definition into a header file, and having every translation unit that needs the definition, include the header file.
#include is similar to import in java. In c/c++ you inlcude the file header not a specific class. There could be more in this file header than just one class.