C++ :: Pointer As Parameter Is Null?

Apr 9, 2014

In my raytracer-project I have the following function:

bool hitObjects(Ray &ray, std::vector<Object *> &objects, Vector3& normal, Material *mat) {
double tmin = K_HUGE_VALUE;
double t;

[Code]....

When I try to run this, I only get the message "Material pointer is null". So, somehow the pointer is null after the hitObjects-function is called, even though it isn't inside that function.

View 6 Replies


ADVERTISEMENT

C# :: Running 2 Separate Queries But Getting Parameter Should Not Be Null

Feb 1, 2015

I am trying to run the following 2 separate queries but keep getting the following error message:

I've looked at the database and the first query is successful (hence the parameter is not null) but it fails at the cmd.ExecuteNonQuery(); in for (var i = 0; i < _waypointList.Count; i++) { ... }

Code below:

var query =
@"INSERT INTO booking (operator_id, plot_id, postcode, datetime, stops, " +
"mileage, price, passengers, name, note, phone, status, reference) " +

[Code]......

View 2 Replies View Related

C++ :: Linked List Node Passed As Parameter / Argument Pointer To Pointer Notation

Jan 17, 2014

I was having problems changing the value of my head node I passed it as an argument as head which would be the address. The parameter was defined as struct node *head. like this

bool deleteNode(struct node *head, struct node *delptr)

I tried manipultaing pointer values to change head node value but it did not work. I saw some code online which used pointer to pointers(in code below) to change head node value it worked I dont fully understand why. Would like better understanding of why.

Would also like to know why the argument call needed &head instead of just head.

remove = deleteNode(&head,found); opposed to remove = deleteNode(head,found);

#include "stdafx.h"
#include<iostream>
struct node{

[Code].....

View 1 Replies View Related

C/C++ :: Initializing Pointer To NULL?

May 17, 2014

So I'm writing a small program for class, and for some reason I keep getting an error when trying to initialize head to NULL. Even threw in the namespace just to see, nothin'.

#ifndef NUMBERLIST_H
#define NUMBERLIST_H
using namespace std;

[Code].....

There's my header file. Not sure what I'm doing wrong with the constructor.

EDIT: Got it to work with nullptr, but still curious why that isn't working

View 2 Replies View Related

C++ :: Create Null Pointer After Using Delete

Aug 7, 2014

In jumping into C++ it says something like this: It's not necessary but when you delete a pointer it's a good idea to reset it as a null pointer. That if your code try's to dereference the pointer after being freed, your program will crash. This happens to a lot of experienced programmers.

This could corrupt users data. delete p_int;
p_int = NULL;

1. If you can deference a pointer after the memory is freed, why can't you just delete the pointer?

2. If you can do 1, how do you delete the pointer using code?

3. Every thing I've read says that free memory is handed out in a sequenced order. I don't believe that is true at all. I may be wrong. Why can't you put the data in any number of places if it will fit. Isn't the compiler smart enough to know where bytes (bits)and pieces are stored?

4. If you storing anything in free memory must use a pointer to it?

5. Can a pointer or something similar be used with stack memory?

View 13 Replies View Related

C++ :: Pointer Pointing To Null Still Executing

Dec 9, 2013

in the below program for both class pointers pointing to null. Class contains normal function executing but class contains virtual function getting segmentation fault.

#include <cstdio>
using namespace std;
class A
{

[Code].....

View 1 Replies View Related

C++ :: Null Destination Pointer Exception

Aug 26, 2014

Here when NonlinearSolver called the constructor,

m_gradient() constructor is called to construct m_gradient, which in turns sets a variable called m_S to NULL(0), then in the assignment operator, because the m_S is NULL, Visual Studio throws an exception saying that destination pointer is null, but it's not fatal. I don't like that to happen because I have to press ignore many many times when the program is debugged, how can I fix this bug (not mine) to avoid the null destination pointer exception?

As an intermediate layer, the function calls boost unbounded array operator = which in turns calls std::copy which results in this error

Code:
NonlinearSolver(solver_type const & solver)
: m_gradient()
, m_function()
, m_projection() {
*this = solver;

[Code] .....

View 3 Replies View Related

C++ ::  check Pointer To Class Object For Null Value?

Feb 14, 2013

lets say I have a pointer p_unit of type c_unit* (c_unit is an a.b.c.)

I have a function that returns a pointer to a new c_unit object:

c_unit * man_add_unit() {
c_unit * local_p_unit;
unsigned short int local_run_code;
print_man_add_menu();
local_run_code = get_a_run_code(); // this bit just gets user input
switch (local_run_code)

[code]....

I assign that to p_unit, then add it to a vector v_units:

p_unit = man_add_unit();
v_units.push_back(p_unit);
cout << "New unit added.
";

The whole program runs on a loop, and another thing the user can do is to print out data on c_unit objects pointed to by v_units. The problem is, in that function up there ^ I give the user the option to go back to main menu without creating a unit.

Since "local_p_unit" is declared but not assigned an initial value, I'm guessing the function would return a "null" pointer (which is what's hanging me up). If I just let this run with the above code, and go to print out the unit data, the program crashes.

I tried to make an if thing with p_unit == 0 but this always returns false and doesn't catch the "bad" unit that will subsequently cause a crash.

Btw, I have considered assigning a reference to a generic c_unit object to that there local_p_unit so it won't return null, then remove pointers to that object from v_units at the end of the loop.. But I know there's got to be a better way.

View 4 Replies View Related

C++ :: Transverse Vector Of Structs - Null Pointer

Mar 14, 2014

struct mystruct{
int n;
};
class mscope{
public:
std::vector<mystruct> mv;

[Code] .....

So I have a vector of structs and I want to traverse it, find a struct that matches a constraint and obtain a pointer to that struct. I made a function for this purpose which takes a number and an empty pointer that will store the reference. However, after function returns the pointer becomes null. What could be causing this?

View 2 Replies View Related

C++ :: Getting Invalid Null Pointer Error Message After Successful Build

Jan 22, 2013

getting an invalid null pointer error message after a successful build. This program is supposed to ask for firstName, lastName, age and maJor and keep doing so until the age that is input is 0 and then the program closes. Here is what I have.

#include <iostream>
#include <string>
using namespace std;

[Code]....

View 3 Replies View Related

C++ :: Which Object Draw Is Being Called In Case Of Pointer Pointing To NULL

Apr 12, 2013

[URL] ....

Which object's draw is being called?

View 6 Replies View Related

C++ :: Void Pointer As A Parameter

Mar 14, 2013

I want to have a function that has a pointer to an int/double/string so I thought I'd use a void pointer like so:

int someFnc(int a, int b, const void *key){
// take care of converting key into appropriate type in here
}

And when I want to use this function I'd like to be able to do something like this:

main{
...
int myKey;
someFnc(1,2,myKey);
]

But I get a compiler error telling me:

invalid conversion from 'int' to 'const void' -[fpermissive]

Do I need to convert myKey into a void pointer before passing it as an argument?

Why does passing myKey like this work?

someFnc(1,2,&myKey);

View 1 Replies View Related

C++ :: Function Pointer With Object As Parameter?

May 30, 2013

I'm making a code that uses a Function pointer. The problem is, when I try to compile appears an error like:

error: no matching function for call to 'rnVector::rnVector()'

Here's part of the code:

phiFunction::phiFunction(double (*f)(rnVector), rnVector (*df)(rnVector)) {
//... Here comes the code stuff...
}

View 12 Replies View Related

C++ :: How To Use Function With Pointer Parameter To Print Array

Jul 20, 2013

The printArray function should take in the dynamically created array and the size of the array as parameters. It should print out the contents of the array.

#include <iostream>
#include <string>
using namespace std;

[Code].....

My problem is that how to write the code to print the array using pointers. I've been stuck for awhile trying to figure it out.

View 2 Replies View Related

C++ :: How To Pass Function Pointer As A Template Parameter

Jun 13, 2013

void extf(int a) { }
template<typename P>
struct A {
// 1
template< void (*F)(P) >
static void call(P arg) {

[Code]...

Why it is not working? What would be a proper way to pass function pointer as a template parameter?

View 6 Replies View Related

C++ :: Class Constructor With String Const Pointer As Parameter

Feb 19, 2013

I know my product.cpp constructor is wrong but how can I set my private variables.

//PRODUCT.h
#ifndef PROJECT1_PRODUCT_H
#define PROJECT1_PRODUCT_H

[Code].....

View 2 Replies View Related

C++ :: Template Function Parameter Passing By Reference Instead Of Copy / Pointer

Sep 19, 2014

Basically I'm trying to pass an object as a reference to the template function, rather than a copy as it's seeing. I'm needing to do this without editing Obj::Call to accommodate a reference as its first parameter, as it'd break other calls.

You'll notice in the following code the object will be destroyed upon passing, while the object defined is still in-scope due to the infinite end loop.

#include <iostream>
#include <string>
using namespace std;
class Obj {
public:
string name;
Obj(string name): name(name) {cout << "create " << this << endl;}

[code]....

In the past I tried ref(), which appeared to stop this happening, however it created a blank copy of the object instead.

View 3 Replies View Related

C++ :: Calling Constructor From Constructor Set Pointer To Null

Jan 25, 2014

VS 2012 / Windows 7 64 bit

class
class myclass {
public:
myclass(){/*stuff here*/}
myclass(int* p) {MyPointer = p; myclass()}

[Code] ....

it works until the myclass(int* p) calls myclass()

then the MyPointer will become CCCCCCCC (NULL value)!

is there a way to stop the second constructor from resetting the pointer value to null?

View 3 Replies View Related

C++ :: Null Terminator Same As Null And Through False Value?

Feb 18, 2014

I am looking at one of the functions of an exercise:

void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {

[code]...

Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?

View 1 Replies View Related

C++ :: Function Parameter Scope - NumArray Not Recognized As Valid Parameter

Sep 28, 2014

My errors are at the end of the program in two function calls within the definition of the InsertByValue function. g++ does not seem to recognize NumArray as a valid parameter.

#include <iostream>
#include <assert.h>
using namespace std;
const int CAPACITY = 20;

/* Displays the content of an int array, both the array and the size of array will be passed as parameters to the function
@param array: gives the array to be displayed
@param array_size: gives the number of elements in the array */
void DisplayArray (int array[], int array_size);

[Code] ....

View 1 Replies View Related

C# :: Session Is Null But Not Null?

Mar 31, 2015

When you login to my site my loginservice which is done by ajax and json make a session called context.Session["Name"]. With BreakPoints it shows that everything is good and the variables are in place. However when I use Session["Name"] it comes out as null.

I will add my code at the bottem not

using System;
using System.Collections.Generic;
using System.Linq;

[Code].....

View 2 Replies View Related

C++ :: Cannot Convert From Int And Missing Default Parameter For Parameter 1

Dec 4, 2013

I am developing new project in Qt with existing MFC project . SO in MFC I have a function which uses SYSTEMTime and return CString.

example

CString getTimestampString( void )
{
SYSTEMTIME systemTime;
CString datestr;

[Code]....

PS -> I cant able to make any changes in lib_know as this library is being used by many other projects..

View 1 Replies View Related

C++ :: Setting Default Parameter Based On Another Parameter?

Jul 2, 2013

Here's my function definition

bool validateNumber(string& text, int min = 0, int max = -1, bool useMin = true,
bool getValid = true)

The code takes the string text, and checks the make sure that the input is valid and safe to convert and use as a number. However, sometimes there is not min, and sometimes there is no max. The lack of min is done by using the parameter useMin, while the lack of max is done by max < min.

My predicament is the following call:
validateNumber(text, -2);

Now, max will be used, even though I don't want it. Ideally, I would want to do something like... int max = (min - 1), ... but that doesn't work. I also can't check to see if the parameter hasn't been changed (that I know of), because the following call would make it look like it hasn't
validateNumber(text, -2, -1);

So the question is, is there a way to do what I want, without having to add in a bool useMax parameter? Or is this my only option? I don't want to do that for simplicity, but if I have to, I have to.

View 3 Replies View Related

C :: Getting Null Pointers In Most Of Functions

Oct 15, 2014

For some reason I keep getting null pointers in most of my functions, and in my convertTime function the numbers are way higher than they should be.

Code:

//Utils.H header file----------------------------------------------

//This function takes the radius of a circle and returns the diameter, the circumference and the area.
int circleStatistics(double radius, double *diameter, double *circumference, double *area);

//This function takes a number of days and returns how many years, weeks and remaining days that is.
int convertTime(int days, int *y, int *w, int *d);

//This function takes a length of time and calculates the dilation of that time at a percentage of the speed of light.
int lorentzTimeDilation(double normalTime, double percentC, double *dilatedTime);

[Code] ....

View 3 Replies View Related

C++ :: Pointing To NULL And 0 The Same Thing?

Apr 13, 2014

Is:

char *endp = NULL;

the same thing as:

char *endp = 0;

?

View 1 Replies View Related

C++ :: Using STRTOK With Null Fields?

Jul 23, 2013

I am beginner in C++ programming. And i was try use STRTOK code with NULL fields, but in ARRAY fields NULL values is skiped. For example:

input text in Memo2:

AnsiString PAT02[100][20];
for (int IndexVRadku02 = 0; IndexVRadku02 < Memo2->Lines->Count ; IndexVRadku02++) {
AnsiString PNF02 = Memo2->Lines->Strings[IndexVRadku02];
char * PN02;

[Code] ....

Result:

Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6

But i need this result:

Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved