Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:43:14+00:00 2026-05-13T18:43:14+00:00

Isn’t a pointer just a reference when you don’t de-reference it? #include stdafx.h #define

  • 0

Isn’t a pointer just a reference when you don’t de-reference it?

#include "stdafx.h"
#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>


std::list<int>* user_defined_func( ) {
    std::cout << "BEGIN: user_defined_func" << std::endl;
    std::list<int>* l = new std::list<int>;

    l->push_back(8);
    l->push_back(0);

    std::cout << "END: user_defined_func" << std::endl;

    return l;
}


bool validate_list(std::list<int> &L1)
{

   std::cout << "BEGIN: validate_list" << std::endl;

   std::list<int>::iterator it1 = L1.begin();

   for(; it1 != L1.end(); ++it1)
   {
      if(*it1<= 1){

         std::cout << "Validation failed because an item in the list was less than or equal to 1." << std::endl;
         std::cout << "END: validate_list" << std::endl;
         return false;
       }
   }

   std::cout << "Test passed because all of the items in the list were greater than or equal to 1" << std::endl;
   std::cout << "END: validate_list" << std::endl;
  return true;
}

BOOST_AUTO_TEST_SUITE( test )
BOOST_AUTO_TEST_CASE( test )
{
   std::list<int>* list1 = user_defined_func();
   BOOST_CHECK_PREDICATE( validate_list, (list1) );
}
BOOST_AUTO_TEST_SUITE_END()

In the line,

BOOST_CHECK_PREDICATE( validate_list, (list1) ); 

above, I was told that I can’t pass pointer to the function expecting reference. I thought that a pointer (that hasn’t been de-referenced) was just an address (i.e. a reference). What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:43:15+00:00Added an answer on May 13, 2026 at 6:43 pm

    Isn’t a pointer just a reference when
    you don’t de-reference it?

    No, a pointer contains a value that is interpreted as a memory address. (Whether it contains a value that is actually a valid memory address is another question)

    A reference is an alias, another way of referring to an existing value.

    int i = 5;
    int* p = &i; // The value in p is the address that i is stored at.
    int& r = i;  // The value in r is 5, because r is an alias of i.
                 //   Whenever you use r, it's as if you typed i, and vice versa.
                 //   (In this scope, anyway).
    
    int sum = i + r; // Identical to i + i or r + i or r + r.
    

    Edit:

    since list1 is a pointer, how do I access the reference…?

    You have two choices. You can derefence the pointer to get at the list it points to:

    std::list<int>* list1 = user_defined_func();
    std::list<int>& list1ref = *list1;
    BOOST_CHECK_PREDICATE( validate_list, list1ref );
    delete list1;
    

    Of course, this could be shortened to:

    std::list<int>* list1 = user_defined_func();
    BOOST_CHECK_PREDICATE( validate_list, *list1 );
    delete list1;
    

    Your validation function could take a pointer instead of a reference (remember to change L1.{something} to L1->{something}):

    bool validate_list(std::list<int>* L1) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 336k
  • Answers 336k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Either: Use projections - Pro: nothing to add - Con:… May 14, 2026 at 3:54 am
  • Editorial Team
    Editorial Team added an answer Bleh.... found the problem, my project was referencing MVCContrib 1.0,… May 14, 2026 at 3:54 am
  • Editorial Team
    Editorial Team added an answer I'm using ant right now for a project that needs… May 14, 2026 at 3:54 am

Related Questions

I have a French site that I want to parse, but am running into
Isn't the use of delegates to help with some asynchronous cases? I tried the
Isn't that an inconsistent behavior? (PHP 5.2.6) <?php $a = new SimpleXMLElement('<a/>'); $a->addAttribute('b', 'One
Isn't it easily possible to construct a PRNG in such a fashion? Why is
Isn’t a class with only static members a kind of singleton design pattern? Is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.