Howerver I got this errors:
I got new error:
error C2512: 'CLParser' : no appropriate default constructor available
error C2512: 'FILE_' : no appropriate default constructor available
If I remove the asterisks in constructor arguments I got this error:
error C2819: type 'FILE_' does not have an overloaded member 'operator ->'
Hey! That's great idea! I didn't think about it yet. It could save a lot of problems. But see this:
1 2 3 4 5 6
MyGlobalClass::MyGlobalClass(int argc, char* argv[])
//: CLPars(globInst), FIle(globInst)
{
CLParser * CLPars( this );
FILE_ * File( this );
}
This will produce error:
error C2512: 'CLParser' : no appropriate default constructor available
error C2512: 'FILE_' : no appropriate default constructor available.
I tired various header for the constructor:
CLParser::CLParser( MyGlobalClass ) ...
CLParser::CLParser( MyGlobalClass *) ...
or
CLParser::CLParser( MyGlobalClass * globInst) ...
however nothing removed the last error...
foo::foo()
{ //at this point all the members are already constructed. Also the base class constructor was invoked
bar asdf(42); //this variable is local to the function
} //it dies here
I make notes to my personal needs, so hopfully I will not repeat that mistake.
How can I get rid of the warning:
warning C4355: 'this' : used in base member initializer list
is there something like directive #define _CRT_SECURE_NO_WARNINGS
This one does not disable this warning.
I have yet one more similar problem with the 'no appropriate default constructor' error. In MyGlobalClass constructor I am having two vectors: sources and destination. I tried to create constructor for SRC to pass pointer to MyGlobalClass. However if I create initiation list to MyGlobalClass constructor initiating sources it prints error
class MyGlobalClass{
public:
// Source *source;
std::vector<SRC> sources;
std::vector<TARGET> destination;
CLParser CLPars;
FILE_ File;
__BITMAP BMP; // just test
// SRC Src;
char * workingPath;
int actualSource;
int actualTarget;
bool getRegEx;
bool readDirectoryFiles;
staticint IsDirectory(std::string path);
MyGlobalClass(int argc, char* argv[]):
CLPars(this), File(this), BMP(this), sources(this) {
/* HERE PRINTS ERROR: error C2664: 'std::vector<_Ty>::vector(const std::allocator<_Ty> &)' : cannot convert parameter 1 from 'MyGlobalClass *const ' to 'const std::allocator<_Ty> &'
with
[
_Ty=SRC
]
Reason: cannot convert from 'MyGlobalClass *const ' to 'const std::allocator<_Ty>'
with
[
_Ty=SRC
]
No constructor could take the source type, or constructor overload resolution was ambiguous
parse3.cpp
s:\temp\c++\algoritmy\processing_args\parse4\parse2\main.h(16): error C2512: '__BITMAP' : no appropriate default constructor available
s:\temp\c++\algoritmy\processing_args\parse4\parse2\global.h(21): error C2664: 'std::vector<_Ty>::vector(const std::allocator<_Ty> &)' : cannot convert parameter 1 from 'MyGlobalClass *const ' to 'const std::allocator<_Ty> &'
with
[
_Ty=SRC
]
Reason: cannot convert from 'MyGlobalClass *const ' to 'const std::allocator<_Ty>'
with
[
_Ty=SRC
]
No constructor could take the source type, or constructor overload resolution was ambiguous
global.cpp
main.h(16): error C2512: '__BITMAP' : no appropriate default constructor available
global.h(21): error C2664: 'std::vector<_Ty>::vector(const std::allocator<_Ty> &)' : cannot convert parameter 1 from 'MyGlobalClass *const ' to 'const std::allocator<_Ty> &'
with
[
_Ty=SRC
]
Reason: cannot convert from 'MyGlobalClass *const ' to 'const std::allocator<_Ty>'
with
[
_Ty=SRC
]
No constructor could take the source type, or constructor overload resolution was ambiguous
fnc.cpp
Build has been canceled. */
CLPars.ParseArgs(argc, argv);
};
};
main.h defines SRC
1 2 3 4 5 6 7
class SRC {
private:
MyGlobalClass * PGloablInstance;
public:
SRC( MyGlobalClass * globInst ):PGloablInstance(globInst){}; // HERE PRINTS ERROR: '__BITMAP' : no appropriate default constructor available
};
__BITMAP bitmap;
Keskiverto: "However, a design where an object A has a list of objects of same type that contains object A itself is dubious. "
Not at all. This is pointer to object, not object. The constructor receives pointer to the parent instance.
I did not realized that this is call of vector constructor. I intended to pass pointer to this to the object of type SRC. So when I add new SRC object into vector, so the SRC constructor should be called. Will you help me to do this here or should I create new question about vector?