function

Is it good to have a member template function inside a non-template class in c++?

I wonder if it is a good practice to have a member template function inside a non-template class in c++? Why? I'm trying to do something like this in classA.h: classA { public: member_func1(); member_func2(); }; in classA.cpp: template <class T> share_func(); classA::member_func1() { call share_func(); } classA::mem...

I keep Getting Control reaches end of non-void function. What am I doing wrong?

location pick(void){ // generates a random location location get; get.x = rand() % FIELD_SIZE + 1; int forY = rand() % FIELD_SIZE +1; switch(forY){ case 1: get.y = 'a'; break; case 2: get.y = 'b'; break; case 3: get.y = 'c'; break; case 4: ...

return an address of a double

i'm having an issue understanding why the following works: void doubleAddr(double* source, double** dest) { *dest = source; } i get a pointer to a double and want to change the double that dest points to: //usage: int main() { double* num; double* dest; doubleAddr(num, &dest); return 0; } thanks in advanc...

In R: How can I know if my packages are up to date ?

Hi all, I am looking for a function that will tell me, for a list of packages, which of them is up to date and which is not (I need it so to trace back an R crash). Thanks, Tal ...

question regarding execution sequence of function in javascript

hello friends my question is i am having two function f1 and f2 and if i want to execute function f2 after execution of f1 how is it possible? ...

How do you return a string from a function correctly in Dynamic C?

I have a program I am trying to debug, but Dynamic C apparently treats strings differently than normal C does (well, character arrays, anyway). I have a function that I made to make an 8 character long (well, 10 to include the \0 ) string of 0s and 1s to show me the contents of an 8-bit char variable. (IE, I give it the number 13, it r...

Returning a local object from a function

Is this the right way to return an object from a function? Car getCar(string model, int year) { Car c(model, year); return c; } void displayCar(Car &car) { cout << car.getModel() << ", " << car.getYear() << endl; } displayCar(getCar("Honda", 1999)); I'm getting an error, "taking address of temporary". Should I use this way:...

system() function in PHP prints variable 2 times.

Stupid question, this code: <?php $variable = system("cat /home/maxor/test.txt"); echo $variable; ?> with file test.txt: blah prints: blah blah What can I do with system() function to not print nothing so I get 1 "blah"??? ...

how to use ln in Java

Hi, I'm trying to use this formula in JAVA : (-ln(1-L))/L I'm not sure how to use ln in java. thanks in advance ...

Initializing objects on the fly

I have a vector called players and a class called Player. And what I'm trying to do is to write: players.push_back(Player(name, Weapon(bullets))); So I want to be able to create players in a loop. But I see an error message says "no matching function for call Player::Player..." Then I've changed that to: Weapon w(bullets); Player p(...

how to load a page and then run a jquery function

on master page i put this code to load page in same master page and then run jqeury function This is my Master Page code <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html x...

Calling a method of a constant object parameter

Here is my code that fails: bool Table::win(const Card &card) { for (int i = 0; i < cards.size(); i++) if (card.getRank() == cards[i].getRank()) return true; return false; } Error message is: passing 'const Card' as 'this' argument of 'int Card::getRank()' discards qualifiers. When I get a copy of the card and change the...

Must declare function prototype in C?

I am kind of new to C (I have prior Java, C#, and some C++ experience). In C, is it necessary to declare a function prototype or can the code compile without it? Is it good programming practice to do so? Or does it just depend on the compiler? (I am running Ubuntu 9.10 and using the GNU C Compiler, or gcc, under the Code::Blocks IDE) ...

Dynamic creation of a pointer function in c++

I was working on my advanced calculus homework today and we're doing some iteration methods along the lines of newton's method to find solutions to things like x^2=2. It got me thinking that I could write a function that would take two function pointers, one to the function itself and one to the derivative and automate the process. This ...

Overriding classes/functions from a .dll.

Say I have class A and class B. B inherits from class A, and implements a few virtual functions. The only problem is that B is defined in a .dll. Right now, I have a function that returns an instance of class A, but it retrieves that from a static function in the .dll that returns an instance of class B. My plan is to call the created ob...

Get function name from DLL

I want to get function name of the exception thrown from dll in asp.net. ...

C++ Newbie: Passing an fstream to a function to read data

I have a text file named num.txt who's only contents is the line 123. Then I have the following: void alt_reader(ifstream &file, char* line){ file.read(line, 3); cout << "First Time: " << line << endl; } int main() { ifstream inFile; int num; inFile.open("num.txt"); alt_reader(inFile, (char*)&num); cout << "...

Javascript new object (function ) vs inline invocation

Is there any considerations to determine which is better practice for creating an object with private members? var object = new function () { var private = "private variable"; return { method : function () { ..dosomething with private; } } } VS var object = function () { ... }(); Basically what ...

variable names in function definition, call and declaration

Hi, I see C books that use the same variable names in the function definition, calling function and declaration. Others use the same variable names in the calling function and in the declaration/prototype but a different one in the definition as in: void blabla(int something); //prototype blabla(something) // calling function inside m...

C++ function pointer as parameter

Hello, I try to call a function which passed as function pointer with no argument, but I can't make it work. void *disconnectFunc; void D::setDisconnectFunc(void (*func)){ disconnectFunc = func; } void D::disconnected(){ *disconnectFunc; connected = false; } ...