Error no appropriate default constructor available

Pages: 12
I got this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class MyGlobalClass{
public:
MyGlobalClass * pGlobInst = this;
std::vector<SRC> sources(1, pGlobInst);
std::vector<TARGET> destination(1, pGlobInst);

CLParser CLPars;
FILE_ File;

__BITMAP BMP;

		static int IsDirectory(std::string path);
		MyGlobalClass(int argc, char* argv[]): 
			CLPars(this), File(this), BMP(this) {
		CLPars.ParseArgs(argc, argv);
		};
};


main.h(16): error C2512: '__BITMAP' : no appropriate default constructor available
global.h(4): error C2355: 'this' : can only be referenced inside non-static member functions
global.h(4): error C2864: 'MyGlobalClass::pGlobInst' : only static const integral data members can be initialized within a class

Why compiler think that the function is static?

global.h(4):
MyGlobalClass * pGlobInst = this;

main.h(16):
SRC( MyGlobalClass * globInst ):PGloablInstance(globInst){};

Last edited on
Why compiler think that the function is static?

It doesn't. You don't pay attention to the details.

ne555 did already tell you in this thread that you should learn and use initialization list. http://www.cprogramming.com/tutorial/initialization-lists-c++.html

I did point out that the std::vector has many constructors and what type of parameters you probably should pass in order get a desired effect.

Your task is to combine these bits of information, rather than copy-paste without thinking.
This information does not help because it cannot work. The design is wrong.
global.h(4): error C2355: 'this' : can only be referenced inside non-static member functions
It does not thing it is static. It tels you where can you use it.
You can use this only inside non-static member functions
As your use context is not within any member function, it is illegal.

global.h(4): error C2864: 'MyGlobalClass::pGlobInst' : only static const integral data members can be initialized within a class
To use default values that way you should have C++11 mode turned on.
Before C++11 you could only initialize static const members like that. And your member is not static and not const at all.
This information does not help because it cannot work. The design is wrong.

What cannot work? What design is wrong? How?

1
2
3
4
5
6
7
8
9
10
class Foo {
  std::vector<Bar> gaz;
public:

  Foo()
  : gaz( 1, Bar( this ) ) // initialize vector gaz via its fill constructor to contain one element
  // The Bar-type object in the element is initialized with a pointer to this Foo object
  {}

};
Last edited on
Topic archived. No new replies allowed.
Pages: 12