Quantcast
Channel: Active questions tagged header - Stack Overflow
Viewing all articles
Browse latest Browse all 646

separate file compilation is correct in vscode but throws undeclared identifier error on compiling [duplicate]

$
0
0

I am reading the book accelerated c++ and wanted to test separate file compilation. It is fine in vscode using clang++ with the -std=c++20 flag but throws an error upon compiling:

// testing.cpp#include <iostream>#include <vector>#include "NamespaceTest.h"int main(){        // unknown type name error and undeclared identifier error for the first and second use of NamespaceTest    NamespaceTest test = NamespaceTest(1,1.2);    std::cout << test.get_member2() << " " << test.get_member() << std::endl;}
// NamespaceTest.h#ifndef GUARD_namespacetest_h#define GUARD_namespacetest_hclass NamespaceTest {        public:        NamespaceTest(int a, double b);        int get_member();        double get_member2();        private:        int member;        double member2;    };#endif
// NamespaceTest.cpp#include "NamespaceTest.h"int NamespaceTest::get_member(){    return NamespaceTest::member;}double NamespaceTest::get_member2(){    return member2;}

I looked up what the error messages mean but did not have an idea on what is wrong. I found some topics on circular dependencies but this does not apply here.


Viewing all articles
Browse latest Browse all 646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>