If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: template for events

Originally Posted by Cambalinho

with 1 parameter. but i still confuse
how we can initializate the m_foo?

What feature of a constructor does all of your code that you post is missing? It is a feature that you should be using, but you never used it. In some ways, this feature is not a requirement, but it is a requirement if any member variables do not have default constructors.

Now given all of that, do you know what this "feature" is that

1) You seem to never use which you should start to use and

2) Is required to initialize members that cannot be default constructed (like the m_foo variable, and the events variable in your class.

?

That is your homework. Believe me, this is covered in beginner C++ books. The code I posted is beginner code, but from the looks of it, you can't fix it. I know it's humbling, but seriously, this indicates that you need to learn the fundamentals before embarking on this other code you're trying to write.

Re: template for events

How do you initialize any member variable when an object is constructed? Note I said initialize, and not assign. Hint -- the initialization occurs before the body of the constructor.

Regards,

Paul McKenzie

Code:

class foo
{
public:
foo(int x);
};

what i see in these class is that we have 1 construtor declaration(not the function, just the declaration) with an int parameter.
i understand, if you complete that construtor with another variable\function. but in these situšao i don't understand how we inicializate the foo
but like you said: imust read more

Re: template for events

Originally Posted by Cambalinho

Code:

class foo
{
public:
foo(int x);
};

what i see in these class is that we have 1 construtor declaration(not the function, just the declaration) with an int parameter.
i understand, if you complete that construtor with another variable\function. but in these situšao i don't understand how we inicializate the foo
but like you said: imust read more

The answer is obvious -- it can be found in any beginner C++ book, on any C++ website, and thousands of posts here.

What is the syntax required to initialize member variables when a constructor is called? It is that simple of a question. I gave you a hint. Do a google search about C++ constructors, initialization and , member variables.

In addition, here is a post directed to you that I made that explains it to you. However it seems you didn't take my advice:

Re: template for events

Originally Posted by Paul McKenzie

The answer is obvious -- it can be found in any beginner C++ book, on any C++ website, and thousands of posts here.

What is the syntax required to initialize member variables when a constructor is called? It is that simple of a question. I gave you a hint. Do a google search about C++ constructors, initialization and , member variables.

In addition, here is a post directed to you that I made that explains it to you. However it seems you didn't take my advice:

Re: template for events

these is what confuse me... you only declare the construtor, you don't do it.

That is because I don't care about creating a program that links. All that needs to be done is to compile the program so that you can fix the compiler errors.

Also, what if the constructor body is in another file somewhere? That code is still supposed to compile, regardless of whether the function body is there or not. This seems to be another fundamental of C++ that seems to have alluded you.

Do you know the difference between compiling and linking? The compiler doesn't care if the function exists or not -- all the compiler cares about is that if you do call the function, its declaration is present (either as a prototype, or the entire function body is present).

For example:

Code:

void Junk();
int main()
{
Junk();
}

This code compiles with no errors. Does it link? No. The reason why it doesn't link is that it is the linker that cares about whether there really is a Junk() function that exists somewhere. The compiler doesn't care at all if Junk() really does exist.

Re: [RESOLVED] template for events

Originally Posted by Paul McKenzie

The code is there for you to compile and to fix the errors. An empty constructor is not an error -- it is perfectly legal.

Regards,

Paul McKenzie

(compile the resource files before link them.)
compiling: convert the source code to object file;
linking: combine the compiled resources files, object files,i think DLL's too, libraries for make the exe.
understood... sorry for something, and thanks for all. your tip was great for i think. thanks
anotherthing: i'm realy sorry, but i can't rate you... sorry about that

Re: [RESOLVED] template for events

Originally Posted by 2kaud

operator overloading, like member functions is per class not per instance.

my problem with these code is that i can't change the Printed() outside of main. like you see in code. if i use the 'void', i get these error:
"C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|21|error: expected initializer before '.' token|"

Re: [RESOLVED] template for events

Originally Posted by Cambalinho

my problem with these code is that i can't change the Printed() outside of main. like you see in code. if i use the 'void', i get these error:
"C:\Users\Joaquim\Documents\CodeBlocks\My Class\main.cpp|21|error: expected initializer before '.' token|"