Skip navigation

Monthly Archives: June 2011

Error 1 error C2825: ‘_Alloc’: must be a class or namespace when followed by ‘::’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1544


Error 2 error C2039: ‘difference_type’ : is not a member of ‘`global namespace” c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1544
Error 3 error C2146: syntax error : missing ‘,’ before identifier ‘difference_type’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1544
Error 4 error C2065: ‘difference_type’ : undeclared identifier c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1544
Error 5 error C2955: ‘std::_Iterator012’ : use of class template requires template argument list c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1548
Error 6 error C2825: ‘_Alloc’: must be a class or namespace when followed by ‘::’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1550
Error 7 error C2039: ‘size_type’ : is not a member of ‘`global namespace” c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1550
Error 8 error C2146: syntax error : missing ‘;’ before identifier ‘_Sizet’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1550
Error 9 error C4430: missing type specifier – int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1550
Error 10 error C2061: syntax error : identifier ‘_Sizet’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1558
Error 11 error C2061: syntax error : identifier ‘_Sizet’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1565
Error 12 error C2146: syntax error : missing ‘;’ before identifier ‘_Myoff’ c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1582
Error 13 error C4430: missing type specifier – int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1582
Error 14 error C4430: missing type specifier – int assumed. Note: C++ does not support default-int c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector 1582

Not really an error, occurs when you misuse STL function swap() by adding a type parameter.

Example of code producing the error:

#include <vector>
using namespace std ;

int main()
{
  int a=7, b=5 ;

  swap<int>(a,b) ; // This should be just swap( a, b ) ; with NO <TYPE>
}

A reference for me


GIT REPO CREATE:
# login to remote server
ssh git@REMOTE_SERVER

# once logged in
mkdir example.git
cd example.git
git --bare init

# TO EXPORT THE SERVER TO THE INTERNET
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#setting-up-a-public-repository

SERVER:
1.  Start up git-daemon &
2.  touch git-daemon-export-ok

CLIENT:
git clone git://myserverip/home/git/example.git



GIT REPO PUSH:
mkdir example
cd example
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@REMOTE_SERVER:example.git
git push origin master




# TO PUSH AT A LATER TIME, USING USER OVERRIDE SETTINGS
$ git config --global user.name "Tekkub"
$ git config --global user.email "tekkub@gmail.com"

# PER REPO BASIS
$ cd my_other_repo
$ git config user.name "Not Tekkub"
$ git config user.email "not@tekkub.net"




# you can only push using ssh
GIT PUSH
========
git push ssh://git@255.10.10.1/home/git/REPO master

FRom:
http://groups.google.com/group/gitorious/browse_thread/thread/978f2b506286f425/1c55538158adf28a




GIT REPO CLONE:

To get the lab #2 starting code base:

1. Download and install the most recent version of msysgit

2. Once you have it installed, open git bash. In git bash:

cd /c
mkdir repodir
cd repodir

git clone git://github.com/username/projectname

Later, to retrieve updates to the code:

git pull git://github.com/username/projectname


That command will pull the latest updates to the code to your machine



see what you added
==================
git status


UNDO adding
===========
git reset --hard






BRANCHING
=========
git branch branchName     # create a new branch from where you are
git checkout branchName   # switch to using the branch

work on the branch then commit it using

PUSH BRANCH
===========
git push ssh://git@255.10.10.1/home/git/repoTest BRANCHNAME

if you do'nt include BRANCHNAME it assumes ou want to push "master".



Cloning a branch
================
XXXXXgit clone git://255.10.10.1/home/git/repoTest master  # gets
you the master branch..

git clone git://255.10.10.1/home/git/repoTest

no WAIT.  the whole point of GIT is you get EVERYTHING.
NO WAIT.  you DON'T.  there ar eREMOTE branches whihc you see by

git branch -r # SHOWS REMOTE BRANCHES

git show-branch # shows you the curent branch and commit summary

git checkout -b (new_branch_name) creates and switches to a branch




To check out the actual code though, after CLONE, you hvae to
git checkout origin/branchName

this also seems to work:
git pull git://255.10.10.1/home/git/repoName branchName

the funy thing is i'm still on *(no branch), not the actual bracn i'm
supposed to be on



VERY OOD USMMARY
http://git.or.cz/course/svn.html




git log



ah, i see.  a remote branch "you never mess with remote branches", -
meaning its somebody elses' bracnh they're working on and is liable
for seroius chagne so why would you formally say you'r echekcing it
out/  you can't.

so you instead can TRACK their bracnh, which is sort of informally
saying "mirror that to me" but you can't formally WORK ON THEIR BRACNH
unless they are commited to HEAD

git checkout --track -b raster-test-mine origin/raster-test

this "branch raster-test-mine set up to track remote branch
refs/remotes/origin/raster-test

the REMOTES branches it seems are REMOTE TO THE REPOSITORY, not to
YOU.  its SOME USER SOMEHWERE IN SPACE that is REMOTE to the SERVER.

so once you work on your branch a bit, you can PUSH your branch ot the
server by commiting etc

Well I always forget this pattern, so without further ado,

#include <ctime>
#include <stdio.h>

tm* getCurrentTime()
{
  static time_t raw ;
  
  // grab the current time
  time( &raw ) ;

  // Now create that timeinfo struct
  static tm* timeinfo ;
  timeinfo = localtime( &raw ) ;

  return timeinfo ;
}

void printCurrentTime()
{
  // write time into timeBuff
  static char timeBuf[ 256 ] ;
  strftime( timeBuf, 255, "%a %b %d %Y %X", getCurrentTime() ) ; // See here for % meanings

  puts( timeBuf ) ;
}

int main()
{
  printCurrentTime() ;
}

C++ pointer to a member function simple example

Original understanding from this


#include <stdlib.h>
#include <iostream>
using namespace std ;

class Obj
{
public:
  double fcn( int p1, int p2 )
  {
    return p1+p2;
  }
};

typedef double (Obj::*  /*AS*/FcnPtrType/*(end of name)*/  )( int, int ) ;

int main()
{
  // Create a pointer to A MEMBER FUNCTION OF THE "Obj" class, THAT RETURNS DOUBLE;
  // WHOSE INSTANCE NAME IS fcnPtr;
  // WHO ACCEPTS 2 ARGUMENTS, BOTH OF TYPE INT
  double (Obj::*  fcnPtr  )( int, int ) = &Obj::fcn ;

  // Let me break that down for you in steps:
  //double (Obj::*  // Create a pointer to A MEMBER FUNCTION OF "Obj" class, THAT RETURNS DOUBLE;
  //fcnPtr  )       // WHOSE INSTANCE NAME IS fcnPtr;
  //( int, int ) ;  // WHO ACCEPTS 2 ARGUMENTS, BOTH OF TYPE INT

  // Function pointer naming syntax is tricky to get the hang of,
  // but the tricky part is the NAME of the function pointer instance
  // is IN BRACKETS, BEFORE the parameter type listing.  This is
  // counter to what you'd normally expect in C++, where the
  // instance name always appears LAST in the line (breaks the
  // principle of least surprise, I suppose).
	
  // Now lets create an object (whose member function we will call
  // via the function pointer)

  Obj obj ;

  printf( "%f\n", (obj.*fcnPtr)( 3, 7 ) ) ;

  return 0;
}

A simple example that shows how to create a thread in C++ on Win32 platform

    #include <Windows.h>
    #include <stdio.h>
    
    struct Point
    {
      float x,y,z ;
    } ;
    
    DWORD WINAPI threadStartPoint( LPVOID data )
    {
      Sleep( 1000 ) ;
      Point *p = (Point*)data ;
      printf( "%f %f %f\n", p->x, p->y, p->z ) ;
      puts( "Thread job done" ) ;
      return 0 ;
    }
    
    // From main
    int main()
    {
      DWORD threadId ;
      Point p ;
      p.x=2, p.y=3, p.z=4 ;
      HANDLE handle = CreateThread( 0, 0, 
        threadStartPoint,
        (LPVOID)&p,
        0,
        &threadId
      ) ;
    
      if( !handle )
      {
        // Thread creation failed
        puts( "start fail\n" );
      }
      else
      {
        printf( "started on threadid=%d\n", threadId ) ;
      }
    
      WaitForSingleObject( handle, 2000 ) ; // wait up to 2000 ms for the other thread to complete before moving on
    
      puts( "main thread Exiting.." ) ;
      //system( "pause" ) ;
    }

Expression: vector iterator not dereferencable

A common problem C++ newbs encounter is

Expression: vector iterator not dereferencable

The deal with this statement is it usually occurs in a program like

#include <iostream>
#include <vector>
#include <deque>
using namespace std ;

int main()
{
  vector<int> a ;

  for( int i = 0 ; i < 10; i++ )
    a.push_back( i );

  for( vector<int>::iterator i = a.begin() ; i != a.end() ; ++i )
  {
    if( *i == 5 )
      a.erase( i ) ; // ERROR!!

    cout << *i << endl ;
  }
}

So on the line that says // ERROR!! is where the source of the problem is.

When you .erase from a std::vector, you actually invalidate all existing iterators. So doing ++i then, once you hit the loop repeat, is invalid now.

To fix this, simply UPDATE i AFTER YOU CALL ERASE like so:

      i = a.erase( i ) ;

What this does is SET i TO BEING THE ELEMENT AFTER THE ONE YOU JUST DELETED. The result is the program works and you don’t get the error.

Full program:

#include <iostream>
#include <vector>
#include <deque>
using namespace std ;

int main()
{
  vector<int> a ;

  for( int i = 0 ; i < 10; i++ )
    a.push_back( i );

  for( vector<int>::iterator i = a.begin() ; i != a.end() ; ++i )
  {
    if( *i == 5 )
      i = a.erase( i ) ; // Better!!

    cout << *i << endl ;
  }
}