Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help with C++ (im new)?

Im a java programmer switching to c++ for the first time and using MS Visual Studio 2010. Im getting the following errors that I dont understand: "Error 5 error C2065: 'CAPACITY' : undeclared identifier"

and

"Error 13 error C2065: 'current_index' : undeclared identifier"

However both of thesee things are declared in my .h file. here is the code:

#include "pgm1.h"

using namespace std;

sequence() {

value_type numbers[CAPACITY];

used=0;

current()= numbers[used];

int current_index=0;

}

void sequence::start(){

current()=numbers[current_index];

}

void sequence::advance(){

current_index+=1;

current()=numbers[current_index];

}

void sequence::insert(const value_type& entry){

if (used!=0){

int i = used-1 ;//counter starts at the end of array

used++;//add one to used to accomadate new length

int temp = current_index-1;

while (i >= temp){

numbers[i+1]=numbers[i];

i--;

}//while the counter is greater than or equal to the current_cell, rewrite the number[counter+1] with the value in numbers[counter]

numbers[current()-1]=entry; //then once all numbers have been moved fill the empty cell with the given value

}//if more than 0 cells have values run the loop

}//end function

/*

void sequence::attach(const value_type& entry){

}

sequence::remove_current( )

size_type size( ) const

bool is_item( ) const

value_type current( ) const

{}*/

and the code for the .h (pre/post conditions not included for brevity):

#include <cstdlib> // Provides size_t

namespace main_savitch_3

{

class sequence

{

public:

// TYPEDEFS and MEMBER CONSTANTS

typedef double value_type;

typedef std::size_t size_type;

static const size_type CAPACITY = 30;

// CONSTRUCTOR

sequence( );

// MODIFICATION MEMBER FUNCTIONS

void start( );

void advance( );

void insert(const value_type& entry);

void attach(const value_type& entry);

void remove_current( );

// CONSTANT MEMBER FUNCTIONS

size_type size( ) const;

bool is_item( ) const;

value_type current( ) const;

private:

value_type data[CAPACITY];

size_type used;

size_type current_index;

};

}

#endif

Update:

This is just a bunch of functions for the sequence class, which stores data in an array. the problems here are not logical issues, but simply compiler errors, context problems and syntax.

1 Answer

Relevance
  • 8 years ago
    Favorite Answer

    recheck GNU GCC ,

    put these on the top

    # include <stdio.h>

    # include <stdlib.h>

    + you din't mention what this program does

    i use codeblocks for C++/C programming... MS Vis Stud shows me unidentified errors often and solving that quite time consuming and i get off the track.

    get this codeblocks-12.11mingw-setup.exe 96mb one from

    http://www.codeblocks.org/downloads/26

    and rewrite and run your code... hope you'll get some idea ...

    and also check this site since you're new to c++

    http://www.cplusplus.com/doc/tutorial/

    Source(s): Self.
Still have questions? Get your answers by asking now.