Is it correct for me to make a clone of testobj in function AddTest below, before i add it to my map? What i want is an user pass testobj to me though AddTest, and after i add it into my map, i do not want to have anything to do with the original testobj anymore. I.e, they are two copies, one belong to Device, one belong to the caller, both has no link to each other.
Also regarding the GetTest method, i prefer to return a raw pointer, as i do not want to force the caller to use smart pointer. And i also do not want the caller to be able to do anything that may change testobj in the map. So i am not sure to return as const reference or make a clone of testobj on the map and return it to the user (but caller need to delete the testobj when it is not used).
I am posting this simplified piece of code that is a bit confusing for me. There are two functions that I call. One shows the expected results but the result of the other one rather puzzles me.
Calling the function sum1 does not change the values stored in the variables val1 and val2. The output of the program is as follows:
val1= 1 ## val2= 10 // before the call of function sum1 val1= 1 ## val2= 10 // after the call of function sum1 sumOfVals= 22
This is quite obvious and as expected and I just pasted this piece of code as an example for better clarification.
However, if I call the function buildLaplacianPyramid and apply a function for Gaussian Blurring, this also effects the cv::Mat passed to the function. The line imshow("M1, after buildLaplacianPyramid",M1); therefore shows an image that is blurred. Since I am not passing a pointer to the cv::Mat I do not understand why this should be happening. I was assuming that there would be a copy of the cv::Mat M1 to be used within the function. Therefore I was expecting the cv::Mat M1 to retain its original value. I was expecting that all changes applied to cv::Mat inputmat within the function would not have any influence on the cv::Mat M1. Just like in my other example with the sum.
Is there a point in dynamically creating a pointer during runtime only to dereference it? (if that is the right term, as in *pointer, depoint it?)
In this case should I perhaps store pointers instead of references?
Inventory.cpp
Code: bool Inventory::addItem(InventoryItem& item) { addItemAmount(item); if (item.getAmount() > 0) { if (hasEmptySlot()) { addNewItem(*item.clone()); return true;
[Code] ....
Also I was wondering, is there some sort of built-in cloning functionality or do I have to write the clone functions myself? When creating new instances I see that I can either pass the constructor properties or a reference to an object of the same type.
For instance:
Code: new InventoryItem(index, name....); new InventoryItem(const InventoryItem&);
Write a constructor that initializes a new inventory object with the values passed as arguments, but which also includes a reasonable default value for each parameter.
two parameters, CImage *pImgSrc and CImage *pImgDst. I think they are class pointers and the function is passed by reference. What should I learn to understand this function and its parameters? How should I use this function? how to use the function with two parameters CImage *pImgSrc and CImage *pImgDst.
that should pass the value decided by the min function to an ofstream object, filewriter, that call the put method to print chars in a tga image file. When I open the file, all I see it is a huge black screen. You may be thinking that the values of blue,green and red are all zero but it is not the case.
With this code:
if (x==50 && y==50) { cout << "Min BGR: " << endl; cout << min (blue*255.0f,255.0f) << ' ' << min (green*255.0f,255.0f) << ' ' << min (red*255.0f,255.0f) << ' ' << x << ' ' << y << endl;
I noticed that when using variadic functions, if I pass the va_arg() as parameter to a function, the parameters get passed in reverse. Is that expected?
For example, the following code outputs Code: 1 2 2 1
I have to write a c++ program with my own function which consists of two parameters (day, month). Function have to return number of days since the begining of this year. Using this function i have to find out how many days are left till birthday (or how many days have passed since last birthday)
This is how far i am:
Code:
#include <iostream> using namespace std; int cikDienu(int diena, int menesis); int main()
when i pass a string pointer to a function such as string *str = new string(""); and pass that string to a handleElement() function e.g. handleElement(str), and i change the value in the function it simply doesn't change when the function exits as though it's passing it by value or something, even though it gives the pointer address.. I've now changed the code to use double pointers and pass the reference of the str pointer and it works but it seems ugly to use double pointers for this.
//handles when a new element is encountered when parsing and adds it to the parse tree bool ParseBlock::handleElement(char cur, string *curString, int count, bool isOperator) { countNode = new ParseNode(count); //keep track of numbers and strings if they exist and insert them if(!curString->empty()){ if(isNumber(*curString)
Essentially, the 'Sequence' below uses linked lists to store data. If 'result' refers to the same sequence as 'seq1' or 'seq2', I want 'result' to refer to a new sequence. This new sequence can be default constructed (no copy of 'seq1' or 'seq2' is required). I can't seem to do this correctly. Also, the prototype of the function cannot be altered.
void fun(const Sequence& seq1, const Sequence& seq2, Sequence& result) { // Check for reference to same sequence. If they are the same, // create new sequence for 'result' to refer to if ((&seq1 == &result) || (&seq2 == &result)) {
Sem is a pointer to semantic which is a struct type variable. I pass the sem into function yylex so i can fill the semantic.i and semantic.s(s points to an array). The problem is that when sem->i = a; is used inside yylex function, sem->s stops showing to the array.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <iostream> using namespace std; union SEMANTIC_INFO
I'm making a .json loader for a project that I'm working on, and to simplify things, I decided to make all the root attributes named in a separate file. Here's my problem: my loading function, Add(const char* id), works just fine when I pass it a string literal.
However, when I use a function that iterates through a vector list, even with the exact same definitions as the literal, it returns the error: std::out_of_range at memory location 0x0026fb30
I've stepped through it with the VS2010 debugger about a hundred times, checked against memory locations, and just have done everything I can think of, all to no avail..
We're assigned a project working with classes and fractions. My goal is to display a fraction in proper from based on 2 arguments passed to a class member function proper();
My strategy was to utilize the greatest common factor between the 2 arguements, then divide both the numerator and denominator by that number and then it would display.
The program actually runs, but only seems to divide the numerator and not the denominator. This in return makes my other class member functions have incorrect comparisons and sums.
Code: #include<iostream> #include<conio.h> class Fraction { friend void compare(Fraction a, Fraction b); friend void sum(Fraction a, Fraction b);
I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?
I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)
My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.
Code: #include <iostream> //I/O using namespace std; #include <fstream> //files using namespace ios; int FileOpen(string fileName) { ifstream oFile (fileName); //attempt to open file
It works, when the object is passed, except for two cases (one where the minus sign shifts) and whenever there is a zero or a negative integer in the denominator.
Also, I'm passing the function like validInput(c);
i need to pass myboard.board (board is in the class Cboard and it is an array of int) to a function in a class called piece however this is troubling . i need to pass it as pointer os that i could change its value here under is my code.
I'm supposed to add two new functions to an existing class that I've written early on: readData(ifstream&)and writeData(ofstream&).
The parameters of the program are: -Create three employee objects as shown, -Create an ofstream object and open a file. Choose any name for the file that you want. Do not ask the user for the file name. Pass just the file name as the parameter (no path) so that your program assumes the file to be in the same folder as your executable file. -Send messages to each of the three Employee objects to write themselves out to the file. -Close the file. ...
If I get writeData(ofstream&) function bit to work! for brevity I've cut all the functions of the class that arent necessary. Here's what I have so far:
Employee.h #pragma once #include<string> using namespace std;
[Code] ....
So I've tried a bunch of different ways to get my objects into the ofstream object to write them to the file, but I'm supposed to use the two new functions somehow...but I'm way lost.