i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct { int x; } void my_function( my_struct** result ) { my_struct* x = new my_struct{ 10 }; //... *result = x; }
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
I'm trying to write a simple Delegate class with a Bind() and Invoke() function. For now it only needs to support a void class function with no parameters. I've searched around and found quite a few exmaples, though, those class are heavily templated and I lose track trying to simplify it.
So far my code is following:
Code: #include <windows.h> class Test { public: void DoSomething() { MessageBox(NULL, L"Test::DoSomething!", NULL, 0);
[Code] ....
The part I am having difficulty with is assigning &Test::DoSomething to the m_Callback variable.
&tObject::DoSomething works, yet _Callback which I pass &Test::DoSomething to does not work.
I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.
C++ Create a Triangle class that has the following member variables: side1 - a double side2 - a double side 3 - a double perimeter area
The class should have the following member functions:
- default constructor that sets the value of all 3 sides of a triangle to 0.0
- a constructor with arguments that accepts values for the three sides of a triangle (member variables) as arguments
- setDimensions - a function that allows the value of the three sides to be entered by the user through the keyboard
- testSides - a function that determines if the 3 values entered can actually be the sides of a triangle. If they do not create a triangle, print the values entered and an appropriate message --The sum of any two side lengths of a triangle must always be greater than the length of the third side: so side 1 + side 2 > side 3 and side 1 + side 3 > side 2 and side 2 + side 3 > side 1 ( all three must be true for the 3 values to make a triangle)
- getSide1 - a function that returns the value of side 1, getSide2 - a function that returns the value of side 2, getSide3 - a function that returns the value of side 3
- getArea - a function that returns the area of a triangle: The formula for the area of a triangle (when the height is not known) is: A = sqrt (p(p-side1)(p-side2)(p-side3)) where p = (side1+side2+side3)/2
- getPerimeter - a function that returns the perimeter of a triangle: Perimeter = side1 + side2+ Side 3
- A displayTriangleInfo function that displays side1, side2, side3, area, and perimeter for a triangle object.
After testing your code for a single object, create an array of 5 triangles. Use a for loop and the setDimensions function to allow the user to set the values for the 3 sides of a triangle, test the vales entered to determine if the 3 create a triangle. If they do create a triangle than use the getArea and getPerimeter functions to calculate the Area and Perimeter for the triangle and use the displayTriangleInfo function to display all of the data for that triangle. If the three values do not create a triangle then print the 3 numbers entered and an appropriate message. In either case the loop should then move on and get the data for the next triangle from the user.
I have to write a program to print pascals triangle and stores it in a pointer to a pointer , which I am not entirely sure how to do. I also have to write the file and read it, then create a binary file. Assignment is attached. I am not the best with programming and especially with pointers. I will post my code below.
Code: #include <stdio.h> #include <stdlib.h> void writePascalTriangle(char *fileName, int heightOfTriangle, int **triangle) { FILE *fp; fp=fopen("writePascalTriangle.txt", "w");
I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:
#include <iostream> #include <cmath> using namespace std; class Point { private: double px; double py;
[Code] .....
How to get void Triangle::setBottomLeftX(const double x) to work.
Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.
a. The location of the bottom left vertex is stored in the member attribute blPoint. b. The top left vertex can be computed from blPoint and the height. c. The bottom right vertex can be computed from blPoint and the length.
I'm trying to pass 2 arrays into a void funtion, and return values to one function.
this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.
#include <iostream> using namespace std; void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize); int main() { int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189}; int numberCount[8] = { 0 };
[code]...
The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.
if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&') for the moment i just need put the address to Variant pointer. but i receive several errors .
I wrote a program with a recursive() called finder. But it dose not work properly,at run time it becomes to a infinite status. How to detect the error at runtime. Here is the code.
#include<stdio.h> void finder(int x,int y); int tot;
[Code] ....
I think the error is the changing value of x after a round of for loop.
I was reading about void as function argument, but I did not fully understand it's meaning in C.
In C++ void foo(void) {} and void foo() {}
are the same. It means no arguments for foo function. But in C it's different. First function means the same as in C++, but second means
In C, an empty parameter list means that the number and type of the function arguments are unknown. But if it is unknown you can't use this arguments if user specifies same. Because here are no variables to store them. So doesn't result are the some? You do not get any arguments. O do I can get this arguments from some hidden variable?
For example.
void foo() { printf("%d", var); } foo(5);
It is very unclear for me. Do this apply to main function too?
int main(void) int main()
or can I use arguments given to int main() like given to int main(int argc, char* argv[])
I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.
#include<iostream> #include<fstream> using namespace std; void bubbleSort(); void selectionSort();
How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.
In my Class:
void Utility::someFunction(int var1, int var2, void customFunction) { int num1 = var1; int num2 = var2;