0

I can't understand why this code gets unresolved externals error.

stack.cpp

#include "stack.h"
#include<iostream>
using namespace std;

template<int i>
st<i>& st<i>::operator=(const st<i> &other){    
    if(this!=&other){
        delete[]anarray;
        anarray=new int[i];
        for(int i=0;i<10;i++)
            anarray[i]=other.anarray[i];}
    return *this;
    }

template<int i>
void st<i>::push(int i2, int val){anarray[i2]=val;}

stack.h

#pragma once


template<int i> 
class st{
public: int  *anarray;

    st(){anarray=new int[i];}
    ~st(){delete[]anarray;};
    st<i>& operator=(const st<i> &other);


    //int& operator[](int i);
    void push(int i, int val);
};

main.cpp

#include<iostream>
#include"stek.h"
using namespace std;

void main(){
    cout<<"----"<<endl;
    st <10> z1; st<10> z2;
    for(int i=0;i<6;i++)
    z1.anarray[i]=2*i;
    z2=z1; for(int i=0;i<6;i++) cout<<z2.anarray[i]<<endl;
    cout<<"----"<<endl;

    system("pause");
}

I know how to implement this so it works, but my question is why this particular example doesn't work.

wdc
  • 2,623
  • 1
  • 28
  • 41
  • Yes `Error 2 error LNK1120: 1 unresolved externals D:\...` `Error 1 error LNK2019: unresolved external symbol "public: class st<10> & __thiscall st<10>::operator=(class st<10> const &)" (??4?$st@$09@@QAEAAV0@ABV0@@Z) referenced in function _main D:\...` – wdc Jul 05 '15 at 12:01
  • What do you mean _"Yes"_? – πάντα ῥεῖ Jul 05 '15 at 12:03
  • Somebody asked could I put full error code, so I replied yes, but he deleted his comment obviously. – wdc Jul 05 '15 at 12:04
  • 2
    Well, the marked duplicate should well explain what's going wrong. Also put such additional information to your question rather than in a comment please. – πάντα ῥεῖ Jul 05 '15 at 12:05

0 Answers0