using 'this' as parameter

Pages: 12
Hi,
I'm having a quite confusing error.

I have class called Level. In this class I construct objects of the class Block. The constructor of Block looks like this:
Block(Level* level, int x, int y);

So in my level I have the following code:
Block b = new Block(this, 0,0);

And that's where I get the following error:
Argument of type 'Level *' is incompatible with parameter of type 'Level *'

I find this confusing because the error says that the argument and the paramter are of the same type. So why are they incompatible?

Thanks for the help
Show the relevant code.
ok, here is some more code (although what I posted is the most important part)

Block.h
1
2
3
4
5
6
7
8
9
10
11
class Block {
protected:
   int x;
   int y;

   Level* level;

public:
   Block(Level* level, int x, int y);

}


Block.cpp
1
2
3
4
5
6
Block::Block(Level* level, int x, int y) {
   this->level = level;

   this->x = x;
   this->y = y;
}


Level.cpp
1
2
3
4
5
6
7
8
9
10
bool Level::generateLevel(int amountOfBeasts) {

   for (int i = 0; i < WIDTH; i++) {
      for (int j = 0; j < HEIGHT; j++) {
         Block b = new Block(this, i,j); // this is the line where I get the error
         grid[i][j] = b;

      }
   }
}
Either
 
Block *b = new Block(this, i,j);
or
 
Block b(this, i,j);
Couldyou maybe give some more explenation about why this should help?

And the error now changed to:
no instance of constructor "Block::Block" matches the argument list
As @helios pointed out this statement

Block b = new Block(this, i,j);

is invalid.

The type of the expression new Block(this, i,j); is Block * but you are trying to initialize an object oif type Block
Ok, thanks, now I got that, what can I do about this new error? :s
Please post the entire compiler output, rather than just one line.
ok, but it's quite long (because of other problems):

1>  SoftBlock.cpp
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(15): error C2061: syntax error : identifier 'Level'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2347: '__w64' : can not be used with type '__w64 Block'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2371: 'size_t' : redefinition; different basic types
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\predefined c++ types (compiler internal)(19) : see declaration of 'size_t'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3): error C2011: 'Block' : 'class' type redefinition
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3) : see declaration of 'Block'

1>  Level.cpp
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(15): error C2061: syntax error : identifier 'Level'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2347: '__w64' : can not be used with type '__w64 Block'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2371: 'size_t' : redefinition; different basic types
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\predefined c++ types (compiler internal)(19) : see declaration of 'size_t'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3): error C2011: 'Block' : 'class' type redefinition
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3) : see declaration of 'Block'
1>  Block.cpp
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(15): error C2061: syntax error : identifier 'Level'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2347: '__w64' : can not be used with type '__w64 Block'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2371: 'size_t' : redefinition; different basic types
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\predefined c++ types (compiler internal)(19) : see declaration of 'size_t'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C2143: syntax error : missing ';' before '*'
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\level.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3): error C2011: 'Block' : 'class' type redefinition
1>          c:\users\matthias\documents\visual studio 2010\projects\beast\beast\block.h(3) : see declaration of 'Block'
1>  Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:04.06
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I don't see the error you mentioned.
Now that you mention it, no :s
It's just that I'm working in visual studio, and there appears a red line under the word "this", and when hovering it shows this is error :s
Maybe if you try fixing as many of the errors as you can, it will make things clearer.
I don't see a semicolon after your class declaration. Is it there?
Do you need a semicolon if the class declaration is the only thing in the header file?
I thought that it was only necessary if it was in the .cpp file and the implementation came after it.
Since #include directives are simply replaced with the contents of the specified file, there's almost always something after the class declaration. And even when there isn't, the semicolon is still required.
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error C2628: 'Block' followed by 'int' is illegal (did you forget a ';'?)


Doesn't VS highlight syntax errors with a red felt tip pen?
So I've placed the semicolons.

@Zephilinox
I would assume that visual studio would do that, but apparently not :s The only red there is is as I described in my previous posts.
I'm trying to figure out what the cause is of all these errors, but they are very confusing to me. Can anyone give some help, or tips?

Any help is very appreciated
These mostly appear to be syntax errors. That's a bit like spelling or grammatical errors in ordinary language - but the compiler is less forgiving.

Without seeing the source code, it's hard to meaningfully comment, except to say that sometimes a huge number of messages might be triggered from a single coding error, so it's generally a good plan to try to fix the first few errors and compile again to see what remains.
Pages: 12