jeudi 28 décembre 2017

Creating header file with function

I am trying to create function in separate header file but getting problem. Here is the code.

//printVec.cpp
#include<vector>
#include<iostream>
#include"printV.h"

void printVec(const std::vector<double> *v1)
{
    std::vector<double>::const_iterator ele;

    std::cout << "elements: \n";

    for (ele = v1->begin(); ele != v1->end(); ++ele)
    {
        std::cout << *ele << " ";
    }
}

//func1.cpp
#include <iostream>
#include<vector>
#include"printV.h"

int main()
{
    std::vector<double> A={1,2,3,4,5,6,7,8,9,10};
    //Displaying vector A and B
    printVec(&A);
    return 0;
}

This is header file.

//printV.h
#ifndef PRINTV_H
#define PRINTV_H
#include<vector>
void printVec(const std::vector<double> *v1);

#endif

I am compiling it using g++ -Wall -Wextra -I <path to header file> printVec.cpp func1.cpp -o prog_matmult -std=c++11, but getting error as undefined reference toprintVec(std::vector > const*)' collect2.exe: error: ld returned 1 exit status `. Can someone comment what is problematic?

Aucun commentaire:

Enregistrer un commentaire