Error C2676 binary '<<': 'std::ostream' does not define this operator or a conversion to...












0















I don't understand the compilation error C2676



for the below code



#ifndef __VEC_3D_H__
#define __VEC_3D_H__

#include <vector>
#include <cmath>

namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;

/// null constructor
Vec3D(void) {}

/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}

inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};

}

#endif


I have put a functionally identical code in another class and it compiles and runs fine. What is wrong here?



EDIT1: corrected BOBVec3d to Vec3D, was a typo



EDIT2: removed using namespace Internal;, it is indeed point-defeating to have it in a header file










share|improve this question




















  • 1





    On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

    – n.m.
    Nov 22 '18 at 11:18






  • 2





    Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

    – molbdnilo
    Nov 22 '18 at 11:37
















0















I don't understand the compilation error C2676



for the below code



#ifndef __VEC_3D_H__
#define __VEC_3D_H__

#include <vector>
#include <cmath>

namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;

/// null constructor
Vec3D(void) {}

/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}

inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};

}

#endif


I have put a functionally identical code in another class and it compiles and runs fine. What is wrong here?



EDIT1: corrected BOBVec3d to Vec3D, was a typo



EDIT2: removed using namespace Internal;, it is indeed point-defeating to have it in a header file










share|improve this question




















  • 1





    On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

    – n.m.
    Nov 22 '18 at 11:18






  • 2





    Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

    – molbdnilo
    Nov 22 '18 at 11:37














0












0








0








I don't understand the compilation error C2676



for the below code



#ifndef __VEC_3D_H__
#define __VEC_3D_H__

#include <vector>
#include <cmath>

namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;

/// null constructor
Vec3D(void) {}

/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}

inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};

}

#endif


I have put a functionally identical code in another class and it compiles and runs fine. What is wrong here?



EDIT1: corrected BOBVec3d to Vec3D, was a typo



EDIT2: removed using namespace Internal;, it is indeed point-defeating to have it in a header file










share|improve this question
















I don't understand the compilation error C2676



for the below code



#ifndef __VEC_3D_H__
#define __VEC_3D_H__

#include <vector>
#include <cmath>

namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;

/// null constructor
Vec3D(void) {}

/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}

inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};

}

#endif


I have put a functionally identical code in another class and it compiles and runs fine. What is wrong here?



EDIT1: corrected BOBVec3d to Vec3D, was a typo



EDIT2: removed using namespace Internal;, it is indeed point-defeating to have it in a header file







c++ operator-overloading






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 14:23







WurmD

















asked Nov 22 '18 at 11:13









WurmDWurmD

627




627








  • 1





    On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

    – n.m.
    Nov 22 '18 at 11:18






  • 2





    Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

    – molbdnilo
    Nov 22 '18 at 11:37














  • 1





    On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

    – n.m.
    Nov 22 '18 at 11:18






  • 2





    Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

    – molbdnilo
    Nov 22 '18 at 11:37








1




1





On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

– n.m.
Nov 22 '18 at 11:18





On a tangential note, all identifiers that conrain two underscores in a row, and all identifiers that start with an underscore and a capital letter, are reserved. Defining such identifiers in your own code is UB.

– n.m.
Nov 22 '18 at 11:18




2




2





Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

– molbdnilo
Nov 22 '18 at 11:37





Putting using namespace Internal; in the header kind of defeats the purpose of having a namespace.

– molbdnilo
Nov 22 '18 at 11:37












2 Answers
2






active

oldest

votes


















1














missing #include <iostream> at the top.



Fixed it.
(Oh what terribly terribly poor compilation errors in C++ can be..)






share|improve this answer


























  • You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

    – not an alien
    Nov 22 '18 at 11:23













  • I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

    – WurmD
    Nov 22 '18 at 13:40













  • I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

    – not an alien
    Nov 22 '18 at 15:07











  • hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

    – WurmD
    Nov 23 '18 at 12:54











  • uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

    – WurmD
    Nov 23 '18 at 14:07





















0














Change BOBVec3d to Vec3D:



BOBVec3D(void) {}
BOBVec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const BOBVec3D& v);


to



Vec3D(void) {}
Vec3D((float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v);





share|improve this answer
























  • sorry about that, was anonymizing the code and missed those entries

    – WurmD
    Nov 22 '18 at 13:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429713%2ferror-c2676-binary-stdostream-does-not-define-this-operator-or-a-conve%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














missing #include <iostream> at the top.



Fixed it.
(Oh what terribly terribly poor compilation errors in C++ can be..)






share|improve this answer


























  • You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

    – not an alien
    Nov 22 '18 at 11:23













  • I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

    – WurmD
    Nov 22 '18 at 13:40













  • I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

    – not an alien
    Nov 22 '18 at 15:07











  • hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

    – WurmD
    Nov 23 '18 at 12:54











  • uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

    – WurmD
    Nov 23 '18 at 14:07


















1














missing #include <iostream> at the top.



Fixed it.
(Oh what terribly terribly poor compilation errors in C++ can be..)






share|improve this answer


























  • You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

    – not an alien
    Nov 22 '18 at 11:23













  • I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

    – WurmD
    Nov 22 '18 at 13:40













  • I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

    – not an alien
    Nov 22 '18 at 15:07











  • hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

    – WurmD
    Nov 23 '18 at 12:54











  • uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

    – WurmD
    Nov 23 '18 at 14:07
















1












1








1







missing #include <iostream> at the top.



Fixed it.
(Oh what terribly terribly poor compilation errors in C++ can be..)






share|improve this answer















missing #include <iostream> at the top.



Fixed it.
(Oh what terribly terribly poor compilation errors in C++ can be..)







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 12:41

























answered Nov 22 '18 at 11:15









WurmDWurmD

627




627













  • You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

    – not an alien
    Nov 22 '18 at 11:23













  • I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

    – WurmD
    Nov 22 '18 at 13:40













  • I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

    – not an alien
    Nov 22 '18 at 15:07











  • hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

    – WurmD
    Nov 23 '18 at 12:54











  • uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

    – WurmD
    Nov 23 '18 at 14:07





















  • You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

    – not an alien
    Nov 22 '18 at 11:23













  • I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

    – WurmD
    Nov 22 '18 at 13:40













  • I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

    – not an alien
    Nov 22 '18 at 15:07











  • hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

    – WurmD
    Nov 23 '18 at 12:54











  • uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

    – WurmD
    Nov 23 '18 at 14:07



















You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

– not an alien
Nov 22 '18 at 11:23







You may want to check out an extension such as Resharper for C++ or Visual Assist X, they make trivial mistakes like this almost impossible to make. As a newbie I found it very helpful. :-)

– not an alien
Nov 22 '18 at 11:23















I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

– WurmD
Nov 22 '18 at 13:40







I installed Visual Assist, and will try it out for a month, but for this question's problem, it didn't help. (I commented the #include <iostream> in the top, saved and compiled it and: dropbox.com/s/bd3my8l3r7bqcrj/DidntHelp.PNG?raw=1

– WurmD
Nov 22 '18 at 13:40















I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

– not an alien
Nov 22 '18 at 15:07





I apologize. I actually use Resharper myself, but many people prefer to use VAX (for performance reasons on large projects, although I have had no issues), so thought I'd mention it as well. I checked your code with Resharper and it did seem to pick it up. Here's a picture.

– not an alien
Nov 22 '18 at 15:07













hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

– WurmD
Nov 23 '18 at 12:54





hm :), you mentioned ReSharper, but you linked to wholetomato.com :) You meant to link to jetbrains.com/resharper-cpp correct?

– WurmD
Nov 23 '18 at 12:54













uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

– WurmD
Nov 23 '18 at 14:07







uuh, I installed resharper and I'm confused about that's wrong on my end. What I see: dropbox.com/s/64verq3shjam969/What.PNG?raw=1 and the top red highlight says: "Precompiled header must be incluided at the top of the source file", and the bottom: dropbox.com/sh/v77svb2aqdzme2a/AABAyZJ6CX5LhcQpqEjajchSa?raw=1 what do you think is missing compared to yours @notanalien?

– WurmD
Nov 23 '18 at 14:07















0














Change BOBVec3d to Vec3D:



BOBVec3D(void) {}
BOBVec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const BOBVec3D& v);


to



Vec3D(void) {}
Vec3D((float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v);





share|improve this answer
























  • sorry about that, was anonymizing the code and missed those entries

    – WurmD
    Nov 22 '18 at 13:16
















0














Change BOBVec3d to Vec3D:



BOBVec3D(void) {}
BOBVec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const BOBVec3D& v);


to



Vec3D(void) {}
Vec3D((float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v);





share|improve this answer
























  • sorry about that, was anonymizing the code and missed those entries

    – WurmD
    Nov 22 '18 at 13:16














0












0








0







Change BOBVec3d to Vec3D:



BOBVec3D(void) {}
BOBVec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const BOBVec3D& v);


to



Vec3D(void) {}
Vec3D((float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v);





share|improve this answer













Change BOBVec3d to Vec3D:



BOBVec3D(void) {}
BOBVec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const BOBVec3D& v);


to



Vec3D(void) {}
Vec3D((float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 11:18









snake_stylesnake_style

1,170410




1,170410













  • sorry about that, was anonymizing the code and missed those entries

    – WurmD
    Nov 22 '18 at 13:16



















  • sorry about that, was anonymizing the code and missed those entries

    – WurmD
    Nov 22 '18 at 13:16

















sorry about that, was anonymizing the code and missed those entries

– WurmD
Nov 22 '18 at 13:16





sorry about that, was anonymizing the code and missed those entries

– WurmD
Nov 22 '18 at 13:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429713%2ferror-c2676-binary-stdostream-does-not-define-this-operator-or-a-conve%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen