Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °
| |
|
|
You are not logged in. #26 2008-01-18 00:16:29
Re: C++: pointers, references and memory leaksIt is an array of 1 dimensional arrays, but in order to be able to create a data structures such as that, you need to define the structure. With an array, you tell the computer "give me an array of size 10". With a (dynamic) matrix, you can't just say "give me a matrix of size 5x4". This is because the memory itself is shaped like an array, but it's not shaped like a matrix. This makes creating arrays more natural than doing so with a matrix. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #27 2008-02-07 16:20:33
Re: C++: pointers, references and memory leaksmy latest topic: Pointers to functions! Code:#include <iostream>
class Dog
{
public:
Dog() {}
~Dog() {}
// method to be pointed to
int bark(long l, double d) { std::cout << "bark " << (l*d) << " times\n"; return 0; }
};
int main()
{
// declare pointer to any dog method that takes a long and a double and returns an int
int (Dog::*p)(long, double);
p = Dog::bark; // bad???
Dog pokey;
(pokey.*p)(2,4);
return 0;
}according to my book, the statement p = Dog::bark; is how you make p point to that method. On my compiler at home (borland) it compiles and works fine. But today I was using a compiler on a computer in my schools computer lab, and it complained about that statement as being an invalid use of a nonstatic method. Last edited by mikau (2008-02-07 16:23:52) A logarithm is just a misspelled algorithm. #28 2008-02-08 00:19:21
Re: C++: pointers, references and memory leaksIt's just a typo I believe. Code:#include <iostream>
class Dog
{
public:
Dog() {}
~Dog() {}
// method to be pointed to
int bark(long l, double d) { std::cout << "bark " << (l*d) << " times\n"; return 0; }
};
int main()
{
// declare pointer to any dog method that takes a long and a double and returns an int
int (Dog::*p)(long, double);
p = &Dog::bark; // bad???
Dog pokey;
(pokey.*p)(2,4);
return 0;
}"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #29 2008-02-08 00:55:19
Re: C++: pointers, references and memory leaksmm... i think you read my post too fast, Ricky! I said I tried that and it didn't work. Last edited by mikau (2008-02-08 00:57:18) A logarithm is just a misspelled algorithm. #30 2008-02-08 01:11:59
Re: C++: pointers, references and memory leaksWhat compilers are you using? Need name and version numbers. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #32 2008-02-08 04:59:50
Re: C++: pointers, references and memory leaks
If you don't know what this means here is a bit of an explanation. The compiler is a program which takes input files (and some addition parameters) and spits out some type of byte-code. Compilers, like any programs, must be run in some form. As with any program, it must be run. Since the compiler typically requires input (namely, code) it must be run from the command line. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #33 2008-02-08 09:09:58
Re: C++: pointers, references and memory leaksthis is weird... Code:GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.the license is apparently about 17 years old... but I seriously doubt they would put a 1991 compiler on a website still in use today. (or at least as of august 2007) A logarithm is just a misspelled algorithm. #34 2008-02-08 11:23:24
Re: C++: pointers, references and memory leaks& is proper, because you want that function's address.
Not really, however it is fairly rare when they are used. See std::sort for a proper example.
Yes, however this does not mean that the compiler is. A license appears from the start date. So if I start a website in 2000 and keep it running till 2008, I would still put a copyright of 2000 on it. "In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..." #35 2008-02-08 12:32:29
Re: C++: pointers, references and memory leaksthanks! A logarithm is just a misspelled algorithm. #36 2008-02-14 18:47:10
Re: C++: pointers, references and memory leaksTodays subject: internal and external linkage!
okay, but they don't explain what a 'translation unit' is. Immediatley after it uses the following listings to demonstrate internal and external linkage Code:int externalInt = 5;
const int j = 10;
int main()
{
return 0;
}second.cpp Code:extern int externalInt; int anExternalInt = 10; const int j = 10; after this it says the externalInt variable defined in line 1 of first.cpp has external linkage. Last edited by mikau (2008-02-14 18:49:56) A logarithm is just a misspelled algorithm. #37 2008-02-14 20:08:41
Re: C++: pointers, references and memory leaksextern makes available the variable accross all cpp files. The Beginning Of All Things To End. The End Of All Things To Come. #38 2008-02-15 02:05:11
Re: C++: pointers, references and memory leaksYeah, but in first.cpp it declares 'external int' without the 'extern' keyword. But, because of its name, I pressume it also is external. A logarithm is just a misspelled algorithm. |